如何做好恢复购买和获得产品是否购买或不? [英] How to do restore purchase and get whether the Product is Purchase or not?
问题描述
我已经实现了应用程序内结算在我的Android应用程序。
在code我用它如下:
I have implemented the in-App Billing in my android App. The code i use it as below :
onCreate方法:
oncreate method:
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是:
And in Button click my code is:
// 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();
}
现在,当我点击恢复购买按钮,我想看看哪些产品是购买与否。这样,我有什么做的?
Now when i click on Restore Purchase Button, I want to see which Product is Purchase or not. So what should i have to do ??
我已经看到了这SO问题:<一href=\"http://stackoverflow.com/questions/8465738/android-in-app-billing-restore-transaction\">this,和<一个href=\"http://stackoverflow.com/questions/8638665/inapp-purchase-restore-transactions-i-am-not-able-to-figure-the-$c$c-out\">this.但没有得到该产品是用于购买用户,哪些不是。
I have seen this SO Question:this, and this. But not getting which product is purchase for that user and which not.
先谢谢了。
推荐答案
此页面解释了应用内结算的详细情况,并提供了魔域示例应用程序下载。请下载示例应用程序,并在 mBillingService.restoreTransactions看();
功能,最有可能它正是你需要的。
This page explains details of in-app billing and offers the "Dungeons" sample application download. Please, download the sample application and look at the mBillingService.restoreTransactions();
function, most probably it does exactly what you need.
这篇关于如何做好恢复购买和获得产品是否购买或不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!