In-app Billing version 3 is available now and lets you sell both in-app items and (since February 2013) subscriptions, including subscriptions with free trials. It is supported by Android 2.2+ devices running the latest version of the Google Play Store (over 90% of active devices).
Bundle bundle = mService.getBuyIntent(3, "com.example.myapp", MY_SKU, ITEM_TYPE_INAPP, developerPayload); PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT); if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) { // Start purchase flow (this brings up the Google Play UI). // Result will be delivered through onActivityResult(). startIntentSenderForResult(pendingIntent, RC_BUY, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0)); }
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == RC_BUY) { int responseCode = data.getIntExtra(RESPONSE_CODE); String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA); String signature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE); // handle purchase here (for a permanent item like a premium upgrade, // this means dispensing the benefits of the upgrade; for a consumable // item like "X gold coins", typically the application would initiate // consumption of the purchase here) } }
Bundle bundle = mService.getPurchases(3, mContext.getPackageName(), ITEM_TYPE_INAPP); if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) { ArrayList mySkus, myPurchases, mySignatures; mySkus = bundle.getStringArrayList(RESPONSE_INAPP_ITEM_LIST); myPurchases = bundle.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST); mySignatures = bundle.getStringArrayList(RESPONSE_INAPP_PURCHASE_SIGNATURE_LIST); // handle items here }
Bundle bundle = mService.getSkuDetails(3, "com.example.myapp", ITEM_TYPE_INAPP, skus); // skus is a Bundle with the list of SKUs to query if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) { List detailsList = bundle.getStringArrayList(RESPONSE_SKU_DETAILS_LIST); for (String details : detailsList) { // details is a JSON string with // SKU details (title, description, price, ...) } }