0

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

创建方法:

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();
            }
        }






    };
};

在 Button 点击​​我的代码是:

//      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();
        }

现在当我点击恢复购买按钮时,我想看看哪个产品是购买的。那我该怎么办??

我看过这个 SO Question: thisthis。但是没有得到该用户购买的产品和不购买的产品。

提前致谢。

4

1 回答 1

1

此页面解释了应用内计费的详细信息,并提供了“地下城”示例应用程序下载。请下载示例应用程序并查看该mBillingService.restoreTransactions();功能,很可能它完全符合您的需要。

于 2012-05-01T09:36:29.563 回答