android - 在 App Purchase RESTORE TRANSACTIONS 中,我无法弄清楚代码

标签 android in-app-purchase

我在我的编码中添加了一个应用程序内购买,它在购买时运行良好,但是当我尝试添加 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/

相关文章:

android - 在 Android NDK 18 上使用什么代替 STL_PORT

android - 在 cordova 插件中获取上下文

android - 在 Codename One 模拟器中测试应用内购买导致空指针异常

ios - 在两个应用程序中保留应用程序内购买?

ios - Facebook Analytics 显示记录的事件过多

in-app-purchase - 应用内 Apple 订阅...找不到有关 "Share your information"功能的信息

Android:如何从 PreferenceActivity/PreferenceFragment 外部打开 ListPreference 对话框?

android - Regex Number 支持 ","或 "/"

android - 如何在 Android 上使用硬件加速视频解码?

android - Android应用内购,沙盒账号测试