如何恢复购买并获取产品是否已购买?

问题描述 投票:0回答:1

我已经在我的 Android 应用程序中实现了应用内计费。我使用的代码如下:

oncreate方法:

startService(new Intent(this, BillingService.class));
    System.out.println(" - - - - CHECK FOR THE PURCHASE PRODUCT - - - - ");
    BillingHelper.setCompletedHandler(mTransactionHandler);

处理程序是:

 public Handler mTransactionHandler = new Handler(){
    public void handleMessage(android.os.Message msg) {
        System.out.println("SEE FOR THE PRODUCTS PURCHASE OR NOT");
        
        Log.i(TAG, "Transaction complete");
        Log.i(TAG, "Transaction status: "+BillingHelper.latestPurchase.purchaseState);
        Log.i(TAG, "Item purchased is: "+BillingHelper.latestPurchase.productId);
        
        // For Premium Pro Purchase
        if(BillingHelper.latestPurchase.productId == "premium_pro"){
            if(BillingHelper.latestPurchase.isPurchased()){
                System.out.println("START OPENING PREMIUM_PRO_BUY CONTENT");
                myPrefs = getApplicationContext().getSharedPreferences("myPrefs",MODE_WORLD_WRITEABLE);
                prefsEditor = myPrefs.edit();                 
                prefsEditor.putBoolean("PREMIUM_PRO_BUY", true); // value to store                 
                prefsEditor.commit(); 
                PREMIUM_PRO_BUY = true;
                System.out.println("NOW.. . .  PREMIUM_PRO_BUY is as PURCHASED. :-)");
                System.out.println("FINISH TO OPENING BLOCK CONTENT");
                //  showItem();
            }
        }
        
        // For Feature Upgrade Purchase
        if(BillingHelper.latestPurchase.productId == "feature_upgrade"){
            if(BillingHelper.latestPurchase.isPurchased()){
                System.out.println("START OPENING FEATURE_UPGRADE_BUY CONTENT");
                myPrefs = getApplicationContext().getSharedPreferences("myPrefs",MODE_WORLD_WRITEABLE);
                prefsEditor = myPrefs.edit();                 
                prefsEditor.putBoolean("FEATURE_UPGRADE_BUY", true); // value to store                 
                prefsEditor.commit(); 
                FEATURE_UPGRADE_BUY = true;
                System.out.println("NOW.. . .  FEATURE_UPGRADE_BUY is as PURCHASED. :-)");
                System.out.println("FINISH TO OPENING BLOCK CONTENT");
                //  showItem();
            }
        }
        
        
        
        
        
        
    };
};

在按钮中单击我的代码是:

//      CODE TO GET PURCHASED
        if(BillingHelper.isBillingSupported()){
            
            BillingHelper.requestPurchase(getApplicationContext(), "feature_upgrade"); // MY OWN
            
        } else {
            Log.i(TAG,"Can't purchase on this device");
            Toast.makeText(getApplicationContext(), "Please check internet and make sure that you have latest GooglePlay App in your Device.", Toast.LENGTH_LONG).show();
        }

现在,当我单击“恢复购买”按钮时,我想查看哪个产品已购买或未购买。那我该怎么办?

我看过这个问题:thisthis。但不知道该用户购买了哪些产品,哪些没有购买。

android in-app-purchase in-app-billing
1个回答
1
投票

此页面解释了应用程序内计费的详细信息,并提供“Dungeons”示例应用程序下载。请下载示例应用程序并查看

mBillingService.restoreTransactions();
功能,它很可能正是您所需要的。

© www.soinside.com 2019 - 2024. All rights reserved.