资源简介

Google Play结算库V2.0.3版本 接入实例,主要实现了接入流程,及支付流程,及调用支付的封装
修复developerPayload重复传值的问题

资源截图

代码片段和文件信息

package com.thinkfly.gp;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.android.billing.BillingManager;
import com.android.billing.LoggerUtil;
import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.SkuDetailsResponseListener;

import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {


    private static LoggerUtil loggerUtil;

    public static final String TAG = MainActivity.class.getSimpleName();

    static {
        loggerUtil = new LoggerUtil();
        loggerUtil.setTag(TAG);
    }

    public static final String SKU_ID = “com.sdk.new.1“;

    private BillingManager mBillingManager;

    private List mSkuDetails = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        mBillingManager = new BillingManager(this new BillingManager.BillingUpdatesListener() {
            @Override
            public void onBillingClientSetupFinished() {

                List skuList = new ArrayList<>();
                skuList.add(SKU_ID);
                handleManagerAndUiReady(BillingClient.SkuType.INAPP skuList);
            }

            @Override
            public void onConsumeFinished(BillingResult billingResult String purchaseToken) {

                loggerUtil.printDebugLog(“Consumption finished. Purchase token: %s result: %s“ purchaseToken billingResult.getResponseCode());

                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    // Successfully consumed so we apply the effects of the item in our
                    // game world‘s logic which in our case means filling the gas tank a bit
                    loggerUtil.printDebugLog(“Consumption successful. Provisioning.“);

                } else {
                    loggerUtil.printDebugLog(“Error while consuming: %1$s“ billingResult.getResponseCode());

                }

                loggerUtil.printDebugLog(“End consumption flow.“);
            }

            @Override
            public void onPurchasesUpdated(List purchases) {

                for (Purchase purchase : purchases) {

                    if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
                        // Acknowledge purchase and grant the item to the user
                    } else if (purchase.getPurchaseState() == Purchase.PurchaseState.PENDING) {
                        // Here you can confirm to the user that they‘ve started the pending
                        /

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-10-16 18:38  GooglePay\
     文件         216  2019-10-15 15:00  GooglePay\.gitignore
     目录           0  2019-10-16 18:39  GooglePay\app\
     文件           8  2019-10-15 15:00  GooglePay\app\.gitignore
     文件         614  2019-10-16 18:39  GooglePay\app\build.gradle
     目录           0  2019-10-15 15:00  GooglePay\app\libs\
     文件         772  2019-10-15 15:00  GooglePay\app\proguard-rules.pro
     目录           0  2019-10-16 18:38  GooglePay\app\src\
     目录           0  2019-10-16 18:38  GooglePay\app\src\androidTest\
     目录           0  2019-10-15 15:03  GooglePay\app\src\androidTest\java\
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\
     文件         688  2019-10-16 10:04  GooglePay\app\src\main\AndroidManifest.xml
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\java\
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\java\com\
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\java\com\thinkfly\
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\java\com\thinkfly\gp\
     文件        5788  2019-10-16 17:58  GooglePay\app\src\main\java\com\thinkfly\gp\MainActivity.java
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\res\
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\res\drawable\
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\res\drawable-v24\
     文件        1914  2019-10-15 15:02  GooglePay\app\src\main\res\drawable-v24\ic_launcher_foreground.xml
     文件        5776  2019-10-15 15:02  GooglePay\app\src\main\res\drawable\ic_launcher_background.xml
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\res\layout\
     文件         514  2019-10-16 09:52  GooglePay\app\src\main\res\layout\activity_main.xml
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\res\mipmap-anydpi-v26\
     文件         276  2019-10-15 15:02  GooglePay\app\src\main\res\mipmap-anydpi-v26\ic_launcher.xml
     文件         276  2019-10-15 15:02  GooglePay\app\src\main\res\mipmap-anydpi-v26\ic_launcher_round.xml
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\res\mipmap-hdpi\
     文件        2963  2019-10-15 15:00  GooglePay\app\src\main\res\mipmap-hdpi\ic_launcher.png
     文件        4905  2019-10-15 15:00  GooglePay\app\src\main\res\mipmap-hdpi\ic_launcher_round.png
     目录           0  2019-10-16 18:38  GooglePay\app\src\main\res\mipmap-mdpi\
............此处省略50个文件信息

评论

共有 条评论