我已成功将应用内购买添加到我的应用中,结果很好:
但if (purchase.getSku().equals("android.test.purchased"))
没有通过,所以我无法使用高级版更新我的用户界面!
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().equals("android.test.purchased"))
无法通过?
谢谢,
Ruchir
答案 0 :(得分:0)
在Security.java
,方法verifyPurchase()
中,添加以下内容:
if (BuildConfig.DEBUG) {
Log.v("myActivity", "Debug :)");
return true;
}
因此,总方法应如下所示:
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);
}