アプリに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);
}
});
}
}