Android 应用内购买付款后崩溃

标签 android in-app-purchase google-play in-app-billing

我已经在我的应用程序中实现了应用程序购买我已经使用“TrivialDrive”示例作为应用程序内结算的第 3 版,我已经使用静态响应测试了应用程序,所有工作都按预期进行。

但是当我从市场下载应用程序时,应用程序在成功购买后崩溃,

我的代码是购买成功

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

    Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
    if (result.isFailure()) {
    complain("Error purchasing: " + result);
    }

    if (purchase != null) {
    if (purchase.getSku().equals(Constants.IN_APP_PURCHASE_PRODUCT_ID)) {
        // bought the premium upgrade!
        String message = getResources().getString(R.string.app_purchase_successful_msg);
        mIsPremium = true;
        updateUi(mIsPremium);
        successAlert(message);
    }
    }
}
};

我已经设置了成功购买的消息,但我看不到这条消息,(意味着那些 linse 没有执行)当我从它成功购买时,应用程序在成功付款后崩溃。

当重新启动应用程序并尝试购买它说已购买的元素时。

我从开发者控制台收到了崩溃报告。

02-09 02:01:13.181: E/AndroidRuntime(11530): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=10001, result=-1, data=Intent { (has extras) }} to activity {com.eknathkadam.grammaruplite/com.webrich.base.ui.GoogleInAppPurchaseActivity}: java.lang.NullPointerException
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3141)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3184)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread.access$1100(ActivityThread.java:130)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.os.Looper.loop(Looper.java:137)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread.main(ActivityThread.java:4745)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at java.lang.reflect.Method.invokeNative(Native Method)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at java.lang.reflect.Method.invoke(Method.java:511)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at dalvik.system.NativeStart.main(Native Method)
**02-09 02:01:13.181: E/AndroidRuntime(11530): Caused by: java.lang.NullPointerException
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.google.billing.Base64.decode(Base64.java:434)**
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.google.billing.Security.generatePublicKey(Security.java:87)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.google.billing.Security.verifyPurchase(Security.java:66)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.google.billing.IabHelper.handleActivityResult(IabHelper.java:437)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at com.webrich.base.ui.GoogleInAppPurchaseActivity.onActivityResult(GoogleInAppPurchaseActivity.java:238)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.Activity.dispatchActivityResult(Activity.java:5192)
02-09 02:01:13.181: E/AndroidRuntime(11530):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3137)
02-09 02:01:13.181: E/AndroidRuntime(11530):    ... 11 more
02-09 02:02:20.610: E/JavaBinder(250): !!! FAILED BINDER TRANSACTION !!!
02-09 02:02:20.638: E/MountService(250): Listener dead
02-09 02:02:20.638: E/MountService(250): Listener dead
02-09 02:02:22.028: E/InputDispatcher(250): channel '41f313f0 com.android.vending/com.android.vending.AssetBrowserActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
02-09 02:03:59.884: E/PowerManagerService(250): Excessive delay setting brightness: 198ms, mask=2 

它在这一行的 onActivityResult() 方法中抛出空指针异常

if (!mHelper.handleActivityResult(requestCode, resultCode, data))

方法是这样的

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);

// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
    // not handled, so handle it ourselves (here's where you'd
    // perform any handling of activity results not related to in-app
    // billing...
    super.onActivityResult(requestCode, resultCode, data);
} else {
    Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}

它在静态响应上工作得很好,但在我从市场购买时崩溃了。

最佳答案

我通过简单地将我的 IabHelper 成员变量 (mHelper) 设为静态

解决了这个问题

关于Android 应用内购买付款后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14785048/

相关文章:

Android studio,调试死循环

android - 在应用程序中使用 adobe air 购买 android

ios - <In App Purchase>如何直接生成SKProduct

android - 如何测试 PACKAGE_REPLACED 事件

android - 如何将图像存储在二维数组中?

android - 在 Android 中进行应用内购买后,谷歌提供的最大 purchaseToken 长度是多少?

java - v7 CardView 阴影在禁用硬件加速的 Android 5.0 上消失

ios - 获取应用内购买产品列表?

android - 在 Google Play 中更新 Android 应用程序需要更改版本和版本代码吗?

android - 应用程序与 Android 设备的兼容性