【问题标题】:How to do restore purchase and get whether the Product is Purchase or not?如何恢复购买并获取产品是否为购买?
【发布时间】:2012-05-01 04:55:51
【问题描述】:

我已经在我的 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();
            }
        }






    };
};

在 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:this 和 this。但没有得到该用户购买了哪些产品,哪些不是。

提前致谢。

【问题讨论】:

    标签: android in-app-purchase in-app-billing


    【解决方案1】:

    This page 解释应用内计费的详细信息并提供“地下城”示例应用程序下载。请下载示例应用程序并查看mBillingService.restoreTransactions(); 函数,它很可能正是您所需要的。

    【讨论】:

    • 谢谢伙计。我看过那个演示。但我希望它能够获得我购买的产品或未购买的产品。好吧,让我再看一遍,但仍然需要帮助。
    • 它只是恢复购买的功能。如果数据库未启动,则用户可以获得恢复购买。但我想要的是获得有关购买或不购买哪个 Product_id 的信息。
    • RESTORE_TRANSACTIONS 向 Android Market 发出请求,要求提供已购买商品的列表,在 onPurchaseStateChange(PurchaseState purchaseState, String itemId, int quantity, long purchaseTime, String developerPayload) 回调中一一出现。如您所见,这里有 itemId 和您可能正在寻找的其他信息。
    • @谢谢。但是如果我使用 restoreTransactionInformation(BillingSecurity.generateNonce());那么呢?
    • 那你就靠自己了。如果有工作样本,你最好使用它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 2022-01-18
    • 2016-01-31
    • 1970-01-01
    相关资源
    最近更新 更多