In-App Billing • Google Play service that lets you sell digital content from inside your applications • Google Play handles all checkout details • Any application that you publish through Google Play can implement In-app Billing • Other stores (Amazon, etc) have similar APIs http://developer.android.com/google/play/billing/index.html
Interprocess Communication • Supports primitives, Parcelables, and some Collection classes • Parcelables must be available to both processes • Synchronous • Multithreading must be dealt with • Exceptions aren’t propogated http://developer.android.com/guide/components/aidl.html
public Inventory queryInventory(boolean querySkuDetails, List moreSkus) throws IabException public Inventory queryInventory(boolean querySkuDetails, List moreItemSkus, List moreSubsSkus) throws IabException public void queryInventoryAsync(boolean querySkuDetails, List moreSkus, QueryInventoryFinishedListener listener) public void queryInventoryAsync(QueryInventoryFinishedListener listener) public void queryInventoryAsync(boolean querySkuDetails, QueryInventoryFinishedListener listener) Query
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) public void enableDebugLogging(boolean enable, String tag) public void enableDebugLogging(boolean enable) public void startSetup(OnIabSetupFinishedListener listener) public void dispose() Misc
RxJava • A library for composing asynchronous and event-based programs by using observable sequences • Parameterized concurrency • Uniform, composable interface https://github.com/ReactiveX/RxJava
Observable consume(List toConsume) • sync/async versions of the method • Listener to be notified of the result • Checked exceptions • Single/multiple product consumption What’s Missing?
final Observable consumeObs = billingService.consume(purchases); consumeObs.subscribe(new Action1() { @Override public void call(Purchase purchase) { // Successful consume } }, new Action1() { @Override public void call(Throwable throwable) { // Show error message } }); Using the API
final Observable consumeObs = billingService.consume(purchases) .subscribeOn(io()) .observeOn(mainThread()); consumeObs.subscribe(new Action1() { @Override public void call(Purchase purchase) { // Successful consume } }); Using the API
final Observable> consumeObs = billingService.consume(purchases).toList() consumeObs.subscribe(new Action1>() { @Override public void call(List purchases) { // Successful consume } }); Using the API
billingService.queryInventory(true) .flatMap(inventory -> just(getPurchases()) .flatMap(purchases -> billingService.consume(purchases)) .subscribe() Using the API (Advanced)
Additional Benefits Your App Google Play App Google Play Server IPC Magic Play Billing Service RxJava Amazon Billing Service Amazon Server Magic Billing Service Polymorphism