Android 向Libgdx项目添加许可代码后崩溃
我要求在我的代码中找到一个导致应用程序崩溃的问题。 我有许可证代码和libgdx代码,可以作为单独的应用程序使用。 我将许可代码原样添加到Libgdx项目的主要活动中。 之后,应用程序在设备上崩溃。 我不知道为什么 Logcat如下所示: 主要活动代码如下:Android 向Libgdx项目添加许可代码后崩溃,android,libgdx,android-lvl,Android,Libgdx,Android Lvl,我要求在我的代码中找到一个导致应用程序崩溃的问题。 我有许可证代码和libgdx代码,可以作为单独的应用程序使用。 我将许可代码原样添加到Libgdx项目的主要活动中。 之后,应用程序在设备上崩溃。 我不知道为什么 Logcat如下所示: 主要活动代码如下: public class MyActivity extends AndroidApplication { private static final String BASE64_PUBLIC_KEY = "!!!!! PLACE YOUR
public class MyActivity extends AndroidApplication {
private static final String BASE64_PUBLIC_KEY = "!!!!! PLACE YOUR KEY HERE!!!!!!";
// Generate your own 20 random bytes, and put them here.
private static final byte[] SALT = new byte[] {
-45, 65, 30, -128, -103, -57, 74, -64, 51, 88, -95, -45, 77, -117, -36, -113, -11, 32, -64,
89
};
private TextView mStatusText;
private Button mCheckLicenseButton;
private LicenseCheckerCallback mLicenseCheckerCallback;
private LicenseChecker mChecker;
// A handler on the UI thread.
private Handler mHandler;
public void onCreate (android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
print("MyLog====","00000000000000000");
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
mStatusText = (TextView) findViewById(R.id.status_text);
mCheckLicenseButton = (Button) findViewById(R.id.check_license_button);
mCheckLicenseButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
doCheck();
}
});
mHandler = new Handler();
// 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);
print("MyLog====","11111111111111");
doCheck();
}
protected Dialog onCreateDialog(int id) {
final boolean bRetry = id == 1;
return new AlertDialog.Builder(this)
.setTitle(R.string.unlicensed_dialog_title)
.setMessage(bRetry ? R.string.unlicensed_dialog_retry_body : R.string.unlicensed_dialog_body)
.setPositiveButton(bRetry ? R.string.retry_button : R.string.buy_button, new DialogInterface.OnClickListener() {
boolean mRetry = bRetry;
public void onClick(DialogInterface dialog, int which) {
if ( mRetry ) {
doCheck();
} else {
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"http://market.android.com/details?id=" + getPackageName()));
startActivity(marketIntent);
}
}
})
.setNegativeButton(R.string.quit_button, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).create();
}
private void displayDialog(final boolean showRetry) {
print("MyLog====","DisplayDialog");
mHandler.post(new Runnable() {
public void run() {
setProgressBarIndeterminateVisibility(false);
showDialog(showRetry ? 1 : 0);
mCheckLicenseButton.setEnabled(true);
}
});
}
private void doCheck() {
mCheckLicenseButton.setEnabled(false);
setProgressBarIndeterminateVisibility(true);
mStatusText.setText(R.string.checking_license);
mChecker.checkAccess(mLicenseCheckerCallback);
}
private void displayResult(final String result) {
print("MyLog====","3333333333333");
mHandler.post(new Runnable() {
public void run() {
print("MyLog====","aaaaaaaaaaaa");
mStatusText.setText(result);
print("MyLog====","bbbbbbbb");
setProgressBarIndeterminateVisibility(false);
print("MyLog====","cccccccc");
mCheckLicenseButton.setEnabled(true);
print("MyLog====","ddddddd");
}
});
}
private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
public void allow(int policyReason) {
print("MyLog====","444444444444444");
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
// Should allow user access.
displayResult(getString(R.string.allow));
// setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// initialize(new Game3(), false);
}
public void dontAllow(int policyReason) {
print("MyLog====","55555555555555555");
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
//displayResult(getString(R.string.dont_allow));
// 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.
// If the reason for the lack of license is that the service is
// unavailable or there is another problem, we display a
// retry button on the dialog and a different message.
displayDialog(policyReason == Policy.RETRY);
}
public void applicationError(int errorCode) {
print("MyLog====","6666666666666666666666");
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.
//if (errorCode==Policy.
String result = String.format(getString(R.string.application_error), errorCode);
displayResult(result);
print("MyLog====","9999999999999999999");
String msg="";
if (errorCode==1) msg="1-NOT_LICENSED";
if (errorCode==2) msg="2-LICENSED_OLD_KEY";
if (errorCode==3) msg="3-ERROR_NOT_MARKET_MANAGED";
if (errorCode==4) msg="4-ERROR_SERVER_FAILURE";
if (errorCode==5) msg="5-ERROR_OVER_QUOTA";
if (errorCode==6) msg="6-ERR";
print("MyLog====",msg);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
mChecker.onDestroy();
}
我已从授权代码中删除我的密钥。
您应该输入代码进行尝试,否则它将是无效的密钥异常。
提前感谢。
AndroidApplication
要求您在onCreate(…)
中初始化(…)
或初始化视图(…)
。因为上面没有包含它,所以我只能假设代码中缺少它
如果您需要一个原生Android UI,则需要使用
initializeForView(…)
获取LibGDX曲面,然后将其插入到视图层次结构中。或者,您可以通过界面从游戏内部触发检查。现在应用程序在初始化(…)libgdx之前崩溃。Logcat不显示行号。这对我来说是一个迷雾。现在是应用程序。应显示授权错误消息。当然libgdx不会启动。稍后,我想在MainActivity中排除Android文本输出。也许我会在render()中的libgdx启动后添加许可检查。顺便说一句,那里有initialize(..)。但是现在已经注释了。您对initialize
的调用在回调(注释)中,而不是在onCreate
中,当您的回调被调用时onCreate
早就消失了。我知道initialize应该在onCreate中。但是现在崩溃了。。。如何避免呢?那么如何称之为许可呢?我们需要运行mChecker.checkAccess(mlicenceckercallback);那么回调将不会在onCreate中发生。我将尝试运行libgdx,然后运行许可检查。嗯。如果有人解释如何正确地向libgdx项目添加许可,那就太好了。我不是第一个挣扎于此的人。我明白初始化应该在onCreate中。所以这段代码无论如何都不起作用。我已经重写了代码。我开始检查许可证,并立即运行初始化。而且它有效!没有撞车!现在我必须使用许可代码进行测试。感谢您提供有关“初始化”的重要说明。