我刚刚在我的应用程序中实现了 android 服务器检查。我正在使用 StrictPolicy 方法,因为盗版版本的下载量是市场上版本的 5 倍,因此我可能有点苦涩......无论如何,我基本上逐字将该方法编码到我的源代码中。但是,当我将开发人员控制台上的许可测试响应切换为许可时,我会看到未经许可的对话框。但是,在 applicationError 方法中,调用了 dontAllow() ,当我注释掉这一行时,未显示未经许可的对话框。我究竟做错了什么?这是我的 MyLicenseCheckerCallback 类。
我在 onCreate 中调用 doCheck,然后在 onResume 中再次调用。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHandler = new Handler();
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();
setContentView(R.layout.main);
...
private void doCheck() {
mChecker.checkAccess(mLicenseCheckerCallback);
}
private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
public void allow() {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
// Should allow user access.
}
public void dontAllow() {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
//Be as annoying as possible
illegalDownload = new IllegalDownloadHandler(speedy.this);
illegalDownload.show();
illegalDownload.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Intent goToMarket = null;
goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.TimothyMilla.SpeedBoost"));
startActivity(goToMarket);
illegalDownload.dismiss();
}
});
// Should not allow access. An app can handle as needed,
// typically by informing the user that the app is not licensed
// and then shutting down the app or limiting the user to a
// restricted set of features.
// In this example, we show a dialog that takes the user to Market.
//showDialog(0);
//onDestroy();
}
@Override
public void applicationError(ApplicationErrorCode errorCode) {
// TODO Auto-generated method stub
dontAllow();
//when I comment the above line out, the unlicensed dialog is not shown.
}
private void displayResult(final String result) {
mHandler.post(new Runnable() {
public void run() {
//dontAllow();
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
//setProgressBarIndeterminateVisibility(false);
}
});
}
}