3
以前的所有內容都是完美的......但是... 今天發生了一些事情,我的許可證檢查器(未觸及一行),並導致我的應用程序崩潰。所以我看到在那個庫的包管理器上有一個更新並且更新了(我也更新了Eclipse)。 我也更新了這些方法,以使它們能夠使用新的更新。 它工作了幾個小時。 這再次停止工作的一些Eclipse的開/關週期後(它編譯但崩潰):許可證檢查器在rev更新後崩潰
這是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)
拋出的錯誤是一個classnotfound異常,你確定你沒有丟失應用程序中的任何lib文件嗎? – david99world 2012-03-16 15:58:25
它工作的很好,然後我關閉了Eclipse並停止工作......編譯器也沒有給出任何錯誤。 – 2012-03-16 16:01:10