简体   繁体   English

Android应用内结算购买活动导致应用崩溃

[英]Android in-app billing purchase activity crashing the app

Android in-app billing purchase activity is crashing the app. Android应用内结算购买活动导致应用崩溃。

i have a in app billing activity that buys subscription for removing ads for 1 month. 我有一个应用程序内结算活动,该活动购买了订阅以删除1个月的广告。

But when i am clicking remove ads button that calls billing activity, the app is crashing. 但是,当我单击调用结算活动的“删除广告”按钮时,该应用程序崩溃了。

Here is my logcat output: 这是我的logcat输出:

12-18 02:07:51.872: E/chromium(694): [ERROR:browser_gpu_channel_host_factory.cc(258)] Failed to init browser shader disk cache.
12-18 02:07:51.883: E/libEGL(694): validate_display:255 error 3008 (EGL_BAD_DISPLAY)
12-18 02:07:51.888: W/cr.media(694): Requires BLUETOOTH permission
12-18 02:07:51.907: W/art(694): Attempt to remove non-JNI local reference, dumping thread
12-18 02:07:51.914: W/AwContents(694): onDetachedFromWindow called when already detached. Ignoring
12-18 02:07:52.278: W/VideoCapabilities(694): Unrecognized profile 2130706433 for video/avc
12-18 02:07:52.310: I/VideoCapabilities(694): Unsupported profile 4 for video/mp4v-es
12-18 02:07:52.316: I/OMXClient(694): Using client-side OMX mux.
12-18 02:07:52.396: I/Ads(694): Starting ad request.

12-18 02:07:52.401: I/Ads(694): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
12-18 02:07:52.408: I/Ads(694): Starting ad request.

12-18 02:07:52.411: I/Ads(694): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
12-18 02:07:52.420: D/OpenGLRenderer(694): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
12-18 02:07:52.439: D/billing(694): In app billing is set up
12-18 02:07:52.542: I/OpenGLRenderer(694): Initialized EGL, version 1.4
12-18 02:07:54.634: D/AndroidRuntime(694): Shutting down VM
12-18 02:07:54.636: E/AndroidRuntime(694): FATAL EXCEPTION: main
12-18 02:07:54.636: E/AndroidRuntime(694): Process: com.ifreedomapp.v3, PID: 694
12-18 02:07:54.636: E/AndroidRuntime(694): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.startIntentSenderForResult(android.content.IntentSender, int, android.content.Intent, int, int, int)' on a null object reference
12-18 02:07:54.636: E/AndroidRuntime(694):  at com.ifreedom.util.IabHelper.launchPurchaseFlow(IabHelper.java:431)
12-18 02:07:54.636: E/AndroidRuntime(694):  at com.ifreedom.util.IabHelper.launchPurchaseFlow(IabHelper.java:347)
12-18 02:07:54.636: E/AndroidRuntime(694):  at com.ifreedom.StatusActivity$4.onClick(StatusActivity.java:379)
12-18 02:07:54.636: E/AndroidRuntime(694):  at android.view.View.performClick(View.java:5204)
12-18 02:07:54.636: E/AndroidRuntime(694):  at android.view.View$PerformClick.run(View.java:21153)
12-18 02:07:54.636: E/AndroidRuntime(694):  at android.os.Handler.handleCallback(Handler.java:739)
12-18 02:07:54.636: E/AndroidRuntime(694):  at android.os.Handler.dispatchMessage(Handler.java:95)
12-18 02:07:54.636: E/AndroidRuntime(694):  at android.os.Looper.loop(Looper.java:148)
12-18 02:07:54.636: E/AndroidRuntime(694):  at android.app.ActivityThread.main(ActivityThread.java:5417)
12-18 02:07:54.636: E/AndroidRuntime(694):  at java.lang.reflect.Method.invoke(Native Method)
12-18 02:07:54.636: E/AndroidRuntime(694):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
12-18 02:07:54.636: E/AndroidRuntime(694):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-18 02:07:57.191: I/GAV3(694): Thread[GAThread,5,main]: No campaign data found.

Here is my subscribe button activity: 这是我的订阅按钮活动:

    bsubscribe.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        if (billing_error == "") {
            if (!isSubscribed)
                mHelper.launchPurchaseFlow(getParent(), SKU_SUBSCRIPTION, 9999, mPurchaseFinishedListener,"");
            else
                Toast.makeText(mContext, getResources().getString(R.string.already_subs), Toast.LENGTH_SHORT).show();
        } else
            Toast.makeText(mContext, "There's some error in billing : " + billing_error, Toast.LENGTH_LONG).show();
    }
});

}

And this is the setbilling function : 这是稳定功能:

private void setInAppBilling() {
mHelper = new IabHelper(mContext, bill_key);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
    public void onIabSetupFinished(IabResult result) {
        if (mHelper == null)
            return;

        if (!result.isSuccess()) {
            Log.d("billing", "probelem in setting billing" + result);
            billing_error = "" + result;
        }
        if (result.isSuccess()) {
            Log.d("billing", "In app billing is set up");
            mHelper.queryInventoryAsync(new IabHelper.QueryInventoryFinishedListener() {

                @Override
                public void onQueryInventoryFinished(IabResult result, Inventory inv) {
                    if (inv.getPurchase(SKU_SUBSCRIPTION) == null) {
                        edit.putBoolean("subscription", false);
                        edit.commit();
                    } else {
                        edit.putBoolean("subscription", true);
                        edit.commit();
                        bsubscribe.setVisibility(View.GONE);
                    }
                }
            });
        }
    }
});
 }

  IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new         IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase info) {
    if (result.isFailure()) {
        Toast.makeText(mContext, getResources().getString(R.string.error_subs), Toast.LENGTH_SHORT).show();
        return;
    }

    if (info.getSku().equals(SKU_SUBSCRIPTION)) {
        Toast.makeText(mContext, getResources().getString(R.string.success_subs), Toast.LENGTH_SHORT).show();
        edit.putBoolean("subscription", true);
        edit.commit();
    }
}
   };

Set billing is called from OnCreate of the activity. 从活动的OnCreate调用设置开票。

The app is crashing when i click remove ads button (bsubscribe) 当我点击“删除广告”按钮(bsubscribe)时,应用崩溃

Hard to say exactly from the code provided but it looks like the call to getParent() is returning null in your onClick method. 很难从提供的代码中确切地说出,但是看起来对getParent()的调用在您的onClick方法中返回了null。 Then at line 431 in IabHelper.java you are calling startIntentSenderForResult on a null object. 然后,在IabHelper.java中的第431行,您正在对空对象调用startIntentSenderForResult

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM