mservice NPE on Android 5.0 devices

与世无争的帅哥 提交于 2020-01-23 18:21:10

问题


I'm having an issue similar to the question found here: Google In-App billing, IllegalArgumentException: Service Intent must be explicit, after upgrading to Android L Dev Preview. I have tried the solution in the suggested answer:https://stackoverflow.com/a/26318757/1489990 but I am getting an issue specifically on my nexus 9 with android 5.0.1 (and I'm assuming this also applies to all devices with android 5.0).

The issue is that with this code:

connection = new ServiceConnection() {


        @Override
        public void onServiceDisconnected(ComponentName name) {
            mservice = null;
            Log.d("PRICE","mservice disconnected");

        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mservice = IInAppBillingService.Stub.asInterface(service);
            Log.d("PRICE","mservice connected");
            if(mservice==null){
                Log.d("PRICE","mservice is null");
            }
        }

    };

on a device without android 5.0 in my log I see "mservice connected". However on my nexus 9 I get none of the log messages, which leads me to believe mservice is null and the cause of my NPE that is generated when I attempt a purchase with this line:

Bundle buyIntentBundle = mservice.getBuyIntent(3, getPackageName(),
                            "images", "inapp", "key");

Any suggestions for how I can fix this issue?

来源:https://stackoverflow.com/questions/27495659/mservice-npe-on-android-5-0-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!