android - 版本更新后许可证检查器崩溃

标签 android android-activity android-lvl

之前的一切都很完美……但是…… 今天我的许可证检查器发生了一些事情(没有触及一行),这导致我的应用程序崩溃。因此,我看到该库的包管理器上有可用的更新并进行了更新(我也更新了 Eclipse)。 我还更新了这些方法,以使它们适用于新的更新。 它工作了几个小时。 在一些 Eclipse 打开/关闭周期再次停止工作后(编译但崩溃):

这是 LicenseCheck.java:

package it.android.smartscreenoffpro;

/*
 * @author Nick Eubanks
 * 
 * Copyright (C) 2010 Android Infinity (http://www.androidinfinity.com)
 *
 */
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.widget.Toast;

import com.google.android.vending.licensing.AESObfuscator;
import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.LicenseCheckerCallback;
import com.google.android.vending.licensing.ServerManagedPolicy;

/*
 * NOTES ON USING THIS LICENSE FILE IN YOUR APPLICATION: 
 * 1. Define the package
 * of you application above 
 * 2. Be sure your public key is set properly  @BASE64_PUBLIC_KEY
 * 3. Change your SALT using random digits 
 * 4. Under AllowAccess, Add your previously used MainActivity 
 * 5. Add this activity to
 * your manifest and set intent filters to MAIN and LAUNCHER 
 * 6. Remove Intent Filters from previous main activity
 */
public class LicenseCheck extends Activity {
    private class MyLicenseCheckerCallback implements LicenseCheckerCallback {

        public void allow(int reason) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // Should allow user access.
            startMainActivity();

        }


        public void applicationError(int errorCode) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }
            // This is a polite way of saying the developer made a mistake
            // while setting up or calling the license checker library.
            // Please examine the error code and fix the error.
            toast("Error: " + errorCode);
            startMainActivity();

        }

        public void dontAllow(int reason) {
            if (isFinishing()) {
                // Don't update UI if Activity is finishing.
                return;
            }

            // Should not allow access. In most cases, the app should assume
            // the user has access unless it encounters this. If it does,
            // the app should inform the user of their unlicensed ways
            // and then either shut down the app or limit the user to a
            // restricted set of features.
            // In this example, we show a dialog that takes the user to Market.
            showDialog(0);
        }
    }
    private static final String BASE64_PUBLIC_KEY = "It is probably better not to post your key in a place like this.";

    private static final byte[] SALT = new byte[] {-90, 65, 70, -128, -103, -57, 74, -64, 51, 99,
        -95, -5, 100, 97, -35, -113, -14, 32, -64, 89};
    private LicenseChecker mChecker;

    // A handler on the UI thread.

    private LicenseCheckerCallback mLicenseCheckerCallback;

    private void doCheck() {

        mChecker.checkAccess(mLicenseCheckerCallback);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Try to use more data here. ANDROID_ID is a single point of attack.
        String deviceId = Secure.getString(getContentResolver(),
                Secure.ANDROID_ID);

        // Library calls this when it's done.
        mLicenseCheckerCallback = new MyLicenseCheckerCallback();
        // Construct the LicenseChecker with a policy.
        mChecker = new LicenseChecker(this, new ServerManagedPolicy(this,
                new AESObfuscator(SALT, getPackageName(), deviceId)),
                BASE64_PUBLIC_KEY);
        doCheck();

    }

    @Override
    protected Dialog onCreateDialog(int id) {
        // We have only one dialog.
        return new AlertDialog.Builder(this)
                .setTitle("Application Not Licensed")
                .setCancelable(false)
                .setMessage(
                        "This application is not licensed. Make sure you are connected to Internet. Please purchase it from Android Market")
                .setPositiveButton("Buy App",
                        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);
                                finish();
                            }
                        })
                .setNegativeButton("Exit",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                finish();
                            }
                        }).create();
    }

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

    private void startMainActivity() {
        startActivity(new Intent(this, ActivityPrincipale.class));  //REPLACE MainActivity.class WITH YOUR APPS ORIGINAL LAUNCH ACTIVITY
        finish();
    }

    public void toast(String string) {
        Toast.makeText(this, string, Toast.LENGTH_SHORT).show();
    }

这是运行时错误:

03-16 16:53:59.198: E/AndroidRuntime(29719): FATAL EXCEPTION: main
03-16 16:53:59.198: E/AndroidRuntime(29719): java.lang.NoClassDefFoundError: it.android.smartscreenoffpro.LicenseCheck$MyLicenseCheckerCallback
03-16 16:53:59.198: E/AndroidRuntime(29719):    at it.android.smartscreenoffpro.LicenseCheck.onCreate(LicenseCheck.java:101)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at android.app.Activity.performCreate(Activity.java:4465)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at android.os.Looper.loop(Looper.java:137)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at android.app.ActivityThread.main(ActivityThread.java:4424)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at java.lang.reflect.Method.invokeNative(Native Method)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at java.lang.reflect.Method.invoke(Method.java:511)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-16 16:53:59.198: E/AndroidRuntime(29719):    at dalvik.system.NativeStart.main(Native Method)

最佳答案

自动开始工作。

关于android - 版本更新后许可证检查器崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9740514/

相关文章:

android - 订阅//取消订阅主题的 Firebase 云消息传递问题

android - 只有 recyclerview 单元格中的图标是可点击的

android - 如何从非 Activity 类启动 Activity?

android - 将付费应用迁移到 Google Play 上的应用内购买

android - 许可证检查器的错误报告 - 这是什么意思?

android - 将参数传递给 gradle Exec 任务

java - 如何设置平板电脑的选项卡布局图标大小

java - 移动到另一个屏幕不起作用

android - 暂停时 Activity 崩溃

android - LicenseChecker checkAccess泄漏ServiceConnection