Android: name = "com. google. android. gms. wallet. api. enabled"
Android: value = "true"/> and then build. gradle dependency under the module Directory Com. google. android. gms: play-services-wallet: 11.8.0
64 K warning may occur when the project uses the rx series retrofit series and relies heavily on google services. Code Writing
Writing code is actually very simple. Just copy and paste it with google's tutorial.
Create an IabHelper instance 'abhelper mHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
// …
String base64EncodedPublicKey;
// Compute your public key and store it in base64EncodedPublicKey
MHelper = new IabHelper (this, base64EncodedPublicKey );
}Here base64EncodedPublicKey refers to the apk key created in the google play console (which is explained below)
Start Service ListeningmHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh no, there was a problem.
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
}
});
Disconnect and release the listener when exiting the interface@Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
Payment Procedure/**
* @ Param act activity
* @ Param sku: The product id of the product created in the Application
* @ Param requestCode onActivityResult
* @ Param listener: Payment listener
* @ Param extraData: An empty string can be passed for parameters.
*/
// Purchase items
MHelper. launchPurchaseFlow (this, SKU GOOGLE_PAY_RESULT,
MPurchaseFinishedListener, "bGoa + V7g/yqDXvKRqq + JTFn4uQZbPiQJo4pf9RzJ ");IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
return;
}
else if (purchase.getSku().equals(SKU_GAS)) {
// consume the gas and update the UI
}
else if (purchase.getSku().equals(SKU_PREMIUM)) {
// give user access to premium content and update the UI
}
}
};
Callback Processingoverride fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == GOOGLE_PAY_RESULT) {
mHelper!!.handleActivityResult(requestCode, resultCode, data)
...
}
}
Here, the basic integration of the Code is complete. Here, it is only a one-time purchase for the integrated application, if you want to integrate consumption, purchase or subscribe to the service, please refer to the official documentation address. If you click the payment dialog box that appears, the code is correct. The failure is only because of some errors in the console.
Console
In fact, this part is based on the reference documentation, but you only need to pay attention to a few pitfalls.
The consumed key can be found in the service and api. Note that to delete spaces, you must test that the payment application must be published. Therefore, no matter which step your project writes, you only need to release it, but do not release the official version. We recommend that you release the alpha version before releasing it.Application classification,Pricing, distribution content, and other columns ensure that no warning is given in the distribution content. Be sure not to select China, Laos, or other countries (as long as there is a question mark next to the country, do not select, because google pay is not supported in these countries !) After the product is successfully released, you can create an in-app product.
Click Version Management> application version management alpha version to create a tester, note: The account currently logged in cannot be directly tested. After being successfully created, you must click the test link below and agree to become a tester. finished console Integration
Testing takes 1 to 2 hours to wait until your application displaysPublished