2011-04-03 27 views
4

我剛剛在我的應用程序中實現了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); 
      } 
     }); 
    } 
} 
+0

這很奇怪。我在這裏使用完全相同的方法,除了我定製了我的LVL庫。但是我的應用程序仍然有一個非常舊的版本(使用基本的股票LVL),我沒有任何問題(只是測試!)。我也嘗試把dontAllow()放在applicationError中,並且仍然沒有問題。確保你正確地複製你的公鑰......這是我對你在代碼中看到的東西的猜測。啊...順便說一句,我也使用ServerManagerPolicy(你說嚴格,但當然你的代碼不是)。啊...你正在填充deviceId,對不對? – davidcesarino 2011-04-24 17:50:35

+0

發生了幾個小時,然後開始工作。沒有更改.. – milosmns 2015-01-11 13:18:23

回答

8

既然你沒有更新我的意見,我的猜測...確保你:

1-正確地複製你的公鑰。

2-populated deviceId,因爲我認爲你是。只要確保因爲你的代碼隱藏了該聲明。但既然它會給你帶來編譯錯誤,我相信你是。

3-改變了開發者控制檯中的響應代碼(你說你有)。

4-最後,包括你在Android清單文件的適當權限:

<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<uses-permission android:name="com.android.vending.CHECK_LICENSE" /> 
+1

修復了這個問題。乾杯! – 2016-07-06 18:18:27

0

我有一個類似的問題,我解決它在Android清單應用程序定義之前放置的權限,也可以仔細閱讀應用程序的版本,如果在市場中上傳,則必須具有相同的版本。

<uses-permission android:name="com.android.vending.CHECK_LICENSE" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" >......