我在我的编码中添加了一个应用程序内购买,它在购买时运行良好,但是当我尝试添加 Restore_Transaction 代码时出现错误并且应用程序关闭,当应用程序被删除并再次安装时,我添加了下面的代码
我在 onCreate 中写了
startService(new Intent(mContext, BillingService.class));
BillingHelper.setCompletedHandler(mTransactionHandler);
if (BillingHelper.isBillingSupported()) {
BillingHelper.restoreTransactionInformation(BillingSecurity
.generateNonce());
}
然后我调用处理程序使用
public Handler mTransactionHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (BillingHelper.latestPurchase.isPurchased()) {
showItem();
}
};
};
private void showItem() {
purchased = Purchased.getPurchaseInfo(getApplicationContext());
if (purchased == null) {
Date d = new Date();
Toast.makeText(getApplicationContext(), "--- Upgrated ---",
Toast.LENGTH_LONG).show();
purchased = new Purchased(getApplicationContext());
purchased.isPurchased = 1;
purchased.purchasedDate = d.getTime();
purchased.save();
Intent intent = new Intent(ActorGenieActivity.this,
SplashScreen.class);
startActivity(intent);
}
}
最佳答案
我找到了问题的答案,感谢 anddev
您必须检查购买是否为空
public static void verifyPurchase(String signedData, String signature) {
ArrayList<VerifiedPurchase> purchases = BillingSecurity.verifyPurchase(
signedData, signature);
if (purchases != null && !purchases.isEmpty()) {
latestPurchase = purchases.get(0);
confirmTransaction(new String[] { latestPurchase.notificationId });
if (mCompletedHandler != null) {
mCompletedHandler.sendEmptyMessage(0);
} else {
Log
.e(
TAG,
"verifyPurchase error. Handler not instantiated. Have you called setCompletedHandler()?");
}
}
}
并且在 Confirm_Notification 中你必须检查
if (notifyIds[0] != null)
关于android - 在 App Purchase RESTORE TRANSACTIONS 中,我无法弄清楚代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8638665/