Lollipop 5.0 Sample License Checker App crashes on

2019-04-11 14:12发布

When running the the sample license check app provided by Google in sdk/extras/google/play_licensing it crashes on the Emulator(AVD) running Lollipop (5.0) (I don't have a phone running 5.0). It works fine on Phone running Kitkat.

On 4.4 Kitkat it gives a warning the

Implicit intents with startService are not safe: Intent { act=com.android.vending.licensing.ILicensingService } 

android.content.ContextWrapper.bindService:538 com.google.android.vending.licensing.LicenseChecker.checkAccess:150 LicActivity.doCheck:126 

I am not sure 5.0 they have moved it from a warning to full blown error.

I don't know how to convert the implicit intent call to an explicit one. It's being called in the LicenceChecker class

   boolean bindResult = mContext
                            .bindService(
                                    new Intent(
                                            new String(
                                               Base64.decode("HEX_TEXT"))),
                                    this, // ServiceConnection.
                                    Context.BIND_AUTO_CREATE);

BASE 64 decodes into com.android.vending.licensing.ILicensingService

I just receive an error message Unfortunately, licence checker has stopped. in a dialog box.

It is showing this message in logcat

java.lang.RuntimeException: Unable to instantiate application com.android.vending.VendingApplication: java.lang.ClassNotFoundException:

 Didn't find class "com.android.vending.VendingApplication" on path: DexPathList[[zip file "/system/app/LicenseChecker/LicenseChecker.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

It's been reported a while back but still no solution

http://code.google.com/p/android/issues/detail?id=61680

2条回答
来,给爷笑一个
2楼-- · 2019-04-11 14:25

Try this

Intent serviceIntent = new Intent(
     new String(Base64.decode("Y29tLmFuZHJvaWQudmVuZGluZy5saWNlbnNpbmcuSUxpY2Vuc2luZ1NlcnZpY2U=")));
     serviceIntent.setPackage("com.android.vending");

     boolean bindResult = mContext
             .bindService(
               serviceIntent,
               this, // ServiceConnection.
               Context.BIND_AUTO_CREATE);
查看更多
Lonely孤独者°
3楼-- · 2019-04-11 14:40

Adding

intent.setPackage("com.android.vending");

to your Intent ensures that it is an explicit intent as required by Android 5.0.

查看更多
登录 后发表回答