2

I'm having 2 main issues, first issue is this:

I had in app billing setup and I was using intelij. I recently switched to Android Studio 1.0 stable and now I am unable to have the in app billing working as it previously was. Specifically the issue is this:

try {
     itemsDescription2.setText(inventory.getSkuDetails("images").getDescription());
     purchaseButton2.setText(inventory.getSkuDetails("images").getPrice());
    }
 catch(NullPointerException e){
    Log.d("PRICE","NPE happened" + e);
    }

The NPE always occurs here. "images" is indeed on my google play developer console as an in app item, and I haven't had any issues before with it. Also, when I initiate a purchase for `"images"' I get a google play dialog that says "The item you are attempting to purchase could not be found".

As the version of google play services in the AndroidMaifest.xml I have 6171000, but in my previous setup in intelij I had been using 4132500. I'm not sure if the version of google play services is relevant, but that is the only thing I can think of that might cause this problem. I tried changing the project to compile with 4.4.2 instead of 5.0 and also changing the google play services version declared in the manifest but the same error happened.

and my second issue is on a device running android 5.0 such as my Nexus 9, I get this error:

12-11 12:42:00.989  21348-21348/simplequiz.nick.com.namethatplanequiz E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: simplequiz.nick.com, PID: 21348
java.lang.RuntimeException: Unable to start activity ComponentInfo{simplequiz.nick.com/com.nick.simplequiz.MainActivity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.android.vending.billing.InAppBillingService.BIND }
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
        at android.app.ActivityThread.access$800(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent {     act=com.android.vending.billing.InAppBillingService.BIND }
        at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1674)
        at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1773)
        at android.app.ContextImpl.bindService(ContextImpl.java:1751)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:538)
        at com.nick.simplequiz.MainActivity.onCreate(MainActivity.java:108)
        at android.app.Activity.performCreate(Activity.java:5933)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)

           

and this is the line in MainActivity where it happens:

bindService(new Intent(
                "com.android.vending.billing.InAppBillingService.BIND"),
                connection, Context.BIND_AUTO_CREATE);

When I try the suggested solution in this question: Google In-App billing, IllegalArgumentException: Service Intent must be explicit, after upgrading to Android L Dev Preview I get an error here when I try to initiate a purchase:

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

The error is a Null Pointer Exception at this line.

And I have also noticed that implementing the solution in the accepted answer of the linked question causes mservice to always be null, the service is never connected.

Any suggestions for what else I can try?

Community
  • 1
  • 1
ez4nick
  • 9,756
  • 12
  • 37
  • 69
  • possible duplicate of [Google In-App billing, IllegalArgumentException: Service Intent must be explicit, after upgrading to Android L Dev Preview](http://stackoverflow.com/questions/24480069/google-in-app-billing-illegalargumentexception-service-intent-must-be-explicit) – rds Aug 14 '15 at 18:47

3 Answers3

0

It could be related with the Google play services library. Do you have the last version installed in your SDK?

Do you use the new gradle configuration? If the first problem occurred after you switched to Android Studio, and nothing else is changed, probably the issue is related with the new gradle configuration. As you said, take a look at how the play services library is integrated (more on this here).

Do you have these problems on Android 5.0 only or on lower versions too?

Alberto Malagoli
  • 1,173
  • 10
  • 14
0

you should check response like (response != BILLING_RESPONSE_RESULT_OK) before moving further. it may solve your problem.

Reference:

ISSUE 41407

Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57
0

Change your MainActivity.onCreate() to call bindService similarly to this:

Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE);
Maria
  • 633
  • 5
  • 12