简体   繁体   English

Android应用程序在Lollipop上崩溃了

[英]Android App crashes on Lollipop

hi I am using google license checker on my app it works on API 19 and below but crashes on lollipop. 嗨我在我的应用程序上使用谷歌许可证检查器它适用于API 19及以下,但在棒棒糖上崩溃。 I saw the code that has to be add to my license check code but I don't know where to put this code or what should I edit. 我看到必须添加到我的许可证检查代码的代码,但我不知道在哪里放置此代码或我应该编辑什么。 here is my code 这是我的代码

log: 日志:

java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.android.vending.licensing.ILicensingService }
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.licensing.ILicensingService }
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.google.android.vending.licensing.LicenseChecker.checkAccess(LicenseChecker.java:150)
at appinventor.ai_drsalmanshah165.Clinical_Examination.Splash.doCheck(Splash.java:103)
at appinventor.ai_drsalmanshah165.Clinical_Examination.Splash.onCreate(Splash.java:51)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
... 10 more

Java code: Java代码:

public class Splash extends Activity {

MyLicenseCheckerCallback mLicenseCheckerCallback;
LicenseChecker mChecker;
byte[] SALT = new byte[] {
         my salt no.             };
     //Handler mHandler;
     String BASE64_PUBLIC_KEY="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoxvDF3HGQtrRch14wCPN6nAxasak8X4shJM6bCumNS+6xRXTnRZOSyAvHNa1145KlE/i1sy/";
     Context mContext;
     IBinder serviceBinder;
     String deviceId;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.splash);

    mLicenseCheckerCallback = new MyLicenseCheckerCallback();
    deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    // Construct the LicenseChecker with a policy.
    mChecker = new LicenseChecker(
        this, (Policy) new ServerManagedPolicy(Splash.this, new AESObfuscator(SALT, getPackageName(), deviceId)),
        BASE64_PUBLIC_KEY);
    doCheck();


}

private class MyLicenseCheckerCallback implements LicenseCheckerCallback {


    @Override
    public void allow(int reason) {
        // TODO Auto-generated method stub
         if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }

        // Toast.makeText(Splash.this, "License Verified", Toast.LENGTH_SHORT).show();
         Intent intent=new Intent(Splash.this,Home.class);
         startActivity(intent);
         finish();

            // Should allow user access.
            // so do nothing
    }

    @Override
    public void dontAllow(int reason) {
        // TODO Auto-generated method stub
         if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
       //  Toast.makeText(Splash.this, "License Verification Failed", Toast.LENGTH_SHORT).show();
         createDialog();
    }

    @Override
    public void applicationError(int errorCode) {
        // TODO Auto-generated method stub

    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    mChecker.onDestroy();
}

private void doCheck() {
       // mCheckLicenseButton.setEnabled(false);
        setProgressBarIndeterminateVisibility(true);
      ///  mStatusText.setText(R.string.checking_license);
        mChecker.checkAccess(mLicenseCheckerCallback);
}

public void createDialog(){
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("PIRACY WARNING");
    builder.setMessage("This application is not licensed. Please purchase it from Android Market.  If you received this message in error, please contact Support.");
    builder.setPositiveButton("Buy Now", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                "http://market.android.com/details?id=" + getPackageName()));
            startActivity(marketIntent);
        }
    });
    builder.setNegativeButton("Quit", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    });
    AlertDialog dialog = builder.create();
    dialog.show();
}
}

and here is the other code which I got that this can solve my problem. 这是我得到的其他代码,这可以解决我的问题。 but don't know where to put it. 但不知道放在哪里。

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);

Waiting for an official solution, the current solution consists in patching Google's LicenseChecker class 等待官方解决方案,目前的解决方案包括修补Google的LicenseChecker类

com.google.android.vending.licensing.LicenseChecker.checkAccess(LicenseChecker.java:150)

like this: 像这样:

new String(
-    Base64.decode("Y29tLmFuZHJvaWQudmVuZGluZy5saWNlbnNpbmcuSUxpY2Vuc2luZ1NlcnZpY2U="))),
+    Base64.decode("Y29tLmFuZHJvaWQudmVuZGluZy5saWNlbnNpbmcuSUxpY2Vuc2luZ1NlcnZpY2U=")))
+    .setPackage("com.android.vending"), // this fix the 'IllegalArgumentException: Service Intent must be explicit'
     this, // ServiceConnection.

Adding package name with statement setPackage("com.android.vending") makes the Intent explicit, ie, 'safe' (as requested by Android Lollipop ) 使用语句setPackage(“com.android.vending”)添加包名称使得Intent显式,即“安全”(根据Android Lollipop的请求)

Note: 注意:

Please pay attention as after modifying LicenseChecker class you must change the min sdk version from 3 to 4 (thanks russellhoff ) 请注意,在修改LicenseChecker类之后,您必须将min sdk版本从3更改为4(感谢russellhoff

Source: 资源:

https://code.google.com/p/android/issues/detail?id=78505#c19 https://code.google.com/p/android/issues/detail?id=78505#c19

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

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