在应用程序内购买的工作,但方法不执行? [英] In app purchases working, but method not executing?

查看:140
本文介绍了在应用程序内购买的工作,但方法不执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用内购买成功添加到我的应用程序,它经过精细:

I have successfully added in app purchases to my app, and it goes through fine:

在这里输入的形象描述

如果(purchase.getSku()。等于(android.test.purchased))不通过,所以我不能更新我的UI与premium版本!

but the if (purchase.getSku().equals("android.test.purchased")) doesn't go through, and so I can't update my UI with the premium version!

    public void buy(View v) {

        mHelper.launchPurchaseFlow(this, "android.test.purchased", 10001,
                mPurchaseFinishedListener, "developerPayLoadString");

    }

    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
            = new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
            if (result.isFailure()) {

                Toast.makeText(MainActivity.this, "Unable to make purchase.", Toast.LENGTH_SHORT).show();
                return;
            } else if (purchase.getSku().equals("android.test.purchased")) {
                Toast.makeText(MainActivity.this, "Successfully bought product!", Toast.LENGTH_SHORT).show();
            }
};

为什么没有如果(purchase.getSku()。等于(android.test.purchased))经历,即使是付款成功?

Why isn't the if (purchase.getSku().equals("android.test.purchased")) going through even though the payment is successful?

谢谢,

Ruchir

推荐答案

Security.java ,方法 verifyPurchase(),补充一点:

 if (BuildConfig.DEBUG) {
            Log.v("myActivity", "Debug :)");
            return true;
        }

所以,总的方法应该是这样的:

So, the total method should look like this:

  public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) {

        if (BuildConfig.DEBUG) {
            Log.v("myActivity", "Debug :)");
            return true;
        }

        if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey) ||
                TextUtils.isEmpty(signature)) {
            Log.e(TAG, "Purchase verification failed: missing data.");
            return false;
        }



        PublicKey key = Security.generatePublicKey(base64PublicKey);
        return Security.verify(key, signedData, signature);
    }

这篇关于在应用程序内购买的工作,但方法不执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆