这是我的课:
import com.google.android.vending.licensing.AESObfuscator;
import com.google.android.vending.licensing.LicenseCheckerCallback;
import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.ServerManagedPolicy;
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;
public class LicenseCheck extends Activity {
private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
@Override
public void allow(int reason) {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
// Should allow user access.
startMainActivity(true);
}
@Override
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 Code: " + errorCode);
startMainActivity(false);
}
@Override
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);
startMainActivity(false);
}
}
private static final String BASE64_PUBLIC_KEY = "PLACE YOUR BASE KEY FROM GOOGLE HERE";
private static final byte[] SALT = new byte[] { 13, 32, 81, 65, 53, 82, 18, 100, -69, -17, 51, 79, -15, 86, -10, -40, 19, 45, 63, -7 };
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 LicenseCheck.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. In order to use this feature Please purchase it from Android Market")
.setPositiveButton("Buy App", new DialogInterface.OnClickListener() {
@Override
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() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).create();
}
@Override
protected void onDestroy() {
super.onDestroy();
mChecker.onDestroy();
}
private void startMainActivity(boolean isLicensed) {
Intent intent = new Intent(this, MainActivity.class);
Bundle b = new Bundle();
b.putBoolean(CommunicationStrings.isLicensed, isLicensed);
intent.putExtras(b); //Put your id to your next Intent
startActivity(intent); // REPLACE MainActivity.class WITH YOUR APPS ORIGINAL LAUNCH ACTIVITY
finish();
}
public void toast(String string) {
Toast.makeText(this, string, Toast.LENGTH_SHORT).show();
}
}
这是日志:
07-06 10:41:02.765: E/AndroidRuntime(24277): FATAL EXCEPTION: main
07-06 10:41:02.765: E/AndroidRuntime(24277): java.lang.NoClassDefFoundError: com.XX.XXXXXXX.LicenseCheck$MyLicenseCheckerCallback
07-06 10:41:02.765: E/AndroidRuntime(24277): at com.ck.autoWiFi3G.LicenseCheck.onCreate(LicenseCheck.java:85)
07-06 10:41:02.765: E/AndroidRuntime(24277): at android.app.Activity.performCreate(Activity.java:5206)
07-06 10:41:02.765: E/AndroidRuntime(24277): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
07-06 10:41:02.765: E/AndroidRuntime(24277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
07-06 10:41:02.765: E/AndroidRuntime(24277): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
07-06 10:41:02.765: E/AndroidRuntime(24277): at android.app.ActivityThread.access$600(ActivityThread.java:140)
07-06 10:41:02.765: E/AndroidRuntime(24277): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
07-06 10:41:02.765: E/AndroidRuntime(24277): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 10:41:02.765: E/AndroidRuntime(24277): at android.os.Looper.loop(Looper.java:137)
07-06 10:41:02.765: E/AndroidRuntime(24277): at android.app.ActivityThread.main(ActivityThread.java:4898)
07-06 10:41:02.765: E/AndroidRuntime(24277): at java.lang.reflect.Method.invokeNative(Native Method)
07-06 10:41:02.765: E/AndroidRuntime(24277): at java.lang.reflect.Method.invoke(Method.java:511)
07-06 10:41:02.765: E/AndroidRuntime(24277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
07-06 10:41:02.765: E/AndroidRuntime(24277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
07-06 10:41:02.765: E/AndroidRuntime(24277): at dalvik.system.NativeStart.main(Native Method)
我发现这篇文章讨论了这个错误:noclassdeferror for inner class MyLicenseCheckerCallback
但这对我没有帮助。我尝试了干净的项目,将 google play 许可证添加为 jar(在构建路径中)文件。没有任何帮助...
可能是什么问题呢?