我剛剛在我的應用程序中實現了android服務器檢查。我使用的是StrictPolicy方法,因爲我可能只是從盜版版本中獲得了5倍的下載量,因爲它在市場上的版本數量...無論如何,我基本上都是將該方法編碼爲我的源代碼。但是,當我將開發人員控制檯上的許可測試響應切換到「許可」時,我會收到未經許可的對話。然而,在applicationError方法中,dontAllow()被調用,當我註釋這條線時,未經許可的對話框不顯示。我究竟做錯了什麼? 這是我的MyLicenseCheckerCallback類。Android許可證檢查直接進入applicationError(...)
我在onCreate中調用doCheck,並再次在onResume中調用doCheck。
@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);
}
});
}
}
這很奇怪。我在這裏使用完全相同的方法,除了我定製了我的LVL庫。但是我的應用程序仍然有一個非常舊的版本(使用基本的股票LVL),我沒有任何問題(只是測試!)。我也嘗試把dontAllow()放在applicationError中,並且仍然沒有問題。確保你正確地複製你的公鑰......這是我對你在代碼中看到的東西的猜測。啊...順便說一句,我也使用ServerManagerPolicy(你說嚴格,但當然你的代碼不是)。啊...你正在填充deviceId,對不對? – davidcesarino 2011-04-24 17:50:35
發生了幾個小時,然後開始工作。沒有更改.. – milosmns 2015-01-11 13:18:23