在应用程序购买工作,但方法不执行? [英] In app purchases working, but method not executing?
本文介绍了在应用程序购买工作,但方法不执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已成功将应用程式购买项目新增至我的应用程式,并且可以正常使用:
I have successfully added in app purchases to my app, and it goes through fine:
但 if(purchase.getSku()。equals(android.test.purchased))
因此我无法使用高级版更新我的UI!
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();
}
};
为什么不是 if(purchase.getSku
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屋!
查看全文