【发布时间】: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