InApp购买RESTORE_TRANSACTIONS,我无法找出代码

Mau*_*k J 11 android in-app-purchase

我在我的编码中添加了一个应用内购买,它在购买时运行良好,但是当我尝试在删除应用程序并再次安装时添加Restore_Transaction代码时出现错误并关闭应用程序,我在下面添加了编码

在onCreate我写道

startService(new Intent(mContext, BillingService.class));
        BillingHelper.setCompletedHandler(mTransactionHandler);

        if (BillingHelper.isBillingSupported()) {
            BillingHelper.restoreTransactionInformation(BillingSecurity
                    .generateNonce());
        }
Run Code Online (Sandbox Code Playgroud)

然后我叫处理程序使用

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);
        }
    }
Run Code Online (Sandbox Code Playgroud)

Mau*_*k J 5

我找到了我的问题的答案,而不是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()?");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

并在Confirm_Notification中你要检查

if (notifyIds[0] != null)
Run Code Online (Sandbox Code Playgroud)