Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Google Play

Anastasiia Karimova edited this page Feb 25, 2015 · 12 revisions

Supported version: In-app Billing Version 3 API

In the Code

  1. Add the corresponding billing permission

    <uses-permission android:name="com.android.vending.BILLING" />
  2. If you want to delegate purchase verification to the library, set verifyMode to VERIFY_EVERYTHING and add your public key

    OpenIabHelper.Options.Builder builder = new OpenIabHelper.Options.Builder();
    builder.setVerifyMode(OpenIabHelper.Options.VERIFY_EVERYTHING);
    builder.addStoreKey(OpenIabHelper.NAME_GOOGLE, googlePlayPublicKey);
    mHelper = new OpenIabHelper(this, builder.build());

    Or
    if you don't want to keep public keys in the code, we strongly recommend you to verify purchases on a server side using Google Play Developer API. To do it, create OpenIabHelper with VERIFY_SKIP option and no public key.

    OpenIabHelper.Options.Builder builder = new OpenIabHelper.Options.Builder();
    builder.setVerifyMode(OpenIabHelper.Options.VERIFY_SKIP);
    mHelper = new OpenIabHelper(context, builder.build());

    Then in the callback in case of success, just sent

    new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
            if(result.isOK)
            if (storeName.equals(OpenIABHelper.NAME_GOOGLE)) {
                youMethodToVerifyPurchaseViaServer(purchase);
            }
        }
    }
  3. Map the SKUs if they are different for the supported stores

    OpenIabHelper.mapSku(SKU_PREMIUM, OpenIabHelper.NAME_GOOGLE, "org.onepf.trivialdrive.gp.premium");
    OpenIabHelper.mapSku(SKU_GAS, OpenIabHelper.NAME_GOOGLE, "org.onepf.trivialdrive.gp.gas");
    OpenIabHelper.mapSku(SKU_INFINITE_GAS, OpenIabHelper.NAME_GOOGLE, "org.onepf.trivialdrive.gp.infinite_gas");
  4. In the proguard configuration file add

     -keep class com.android.vending.billing.**
    

Test

Google instructions https://developer.android.com/google/play/billing/billing_testing.html

To test .apk, please ensure that

  • for Google Play environment

    • your .apk is submitted to Google Play Developer Console
    • versionCode in AndroidManifest.xml of your .apk is equal to versionCode of .apk submitted to Developer Console
  • for OpenIAB

    # install for Google Play:
    adb install -i com.android.vending /path/to/YourApp.apk

Issues related to Google Play

Useful Links