2013-08-18 2 views
0

내 응용 프로그램에 라이센스 지원을 추가하려고했지만 오류가 발생하지 않았습니다. 그러나 logcat은 라이센스를 확인하고 있지만, 앱에서 무엇이든 할 수 있습니다. 응용 프로그램이 열리면 라이센스를 먼저 확인해야합니다. 내가 얻은 마지막 logcat 항목은 "Received Response"와 "Clearing timeout"입니다. 응답을 NOT_LICENSED 또는 LICENSED로 설정하면 어떤 일을하기 위해 설정 한 실제 처리 중 아무 것도 수행하지 않습니다.이 설정은 기록하도록 설정했습니다. 내가 새로운 개발자로서 보지 못한 것은 아마도 눈부신 문제 일 것입니다. 예 라이브러리를 올바르게 가져 왔습니다.라이선스 또는 라이센스를 반환 할 수있는 라이센스를 얻을 수 없습니다.

public class MainActivity extends ListActivity { 

public static final String PREFS_NAME = "MyPrefsFile"; 
private ArrayAdapter<String> adapter; 
private ListView list; 
private Context c = this; 
boolean home; 
boolean school; 

boolean licensed = false; 
boolean didCheck = false; 
boolean checkingLicense = false; 

SharedPreferences userIsLicensed=null; 

@SuppressWarnings("deprecation") 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main);  

    userIsLicensed = getSharedPreferences(PREFS_NAME, 0);  
    licensed = userIsLicensed.getBoolean("licensed", false); 

    Toast.makeText(this, "Checking application license...", Toast.LENGTH_SHORT).show(); 
    // Check the license 
    checkLicense(); 

// 라이센스 확인 부

String BASE64_PUBLIC_KEY = "KEY"; 

    LicenseCheckerCallback mLicenseCheckerCallback; 
    LicenseChecker mChecker; 

    Handler mHandler; 

    // REPLACE WITH YOUR OWN SALT , THIS IS FROM EXAMPLE 
    private final byte[] SALT = new byte[]{BYTES}; 

    private void displayResult(final String result) { 
     mHandler.post(new Runnable() { 
      public void run() { 

       setProgressBarIndeterminateVisibility(false); 

      } 
     }); 
    } 

    protected void doCheck() { 

     didCheck = false; 
     checkingLicense = true; 
     setProgressBarIndeterminateVisibility(true); 

     mChecker.checkAccess(mLicenseCheckerCallback); 
    } 

    protected void checkLicense() { 

     Log.i("LICENSE", "checkLicense"); 
     mHandler = new Handler(); 

     // Try to use more data here. ANDROID_ID is a single point of attack. 
     String deviceId = Settings.Secure.getString(getContentResolver(), Settings.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); 
     doCheck(); 
    } 

    protected class MyLicenseCheckerCallback implements LicenseCheckerCallback { 

     public void allow() { 
      if (isFinishing()) { 
       // Don't update UI if Activity is finishing. 
       return; 
      } 

      Log.i("License","Accepted!"); 
      // Should allow user access. 
      displayResult(getString(R.string.allow)); 
      licensed = true; 
      checkingLicense = false; 
      didCheck = true; 

      SharedPreferences.Editor editor = userIsLicensed.edit(); 
      editor.putBoolean("licensed", true); 
      editor.commit(); 

      Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName()); 
      i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      startActivity(i); 

     } 

     @SuppressWarnings("deprecation") 
     public void dontAllow() { 
      if (isFinishing()) { 
       // Don't update UI if Activity is finishing. 
       return; 
      } 
      Log.i("License","Denied!"); 
      displayResult(getString(R.string.dont_allow)); 
      licensed = false; 
      // 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. 
      checkingLicense = false; 
      didCheck = true; 

      SharedPreferences.Editor editor = userIsLicensed.edit(); 
      editor.putBoolean("licensed", false); 
      editor.commit(); 

      showDialog(0); 
     } 

     @SuppressWarnings("deprecation") 
     public void applicationError(ApplicationErrorReport errorCode) { 
      Log.i("LICENSE", "error: " + errorCode); 
      if (isFinishing()) { 
       // Don't update UI if Activity is finishing. 
       return; 
      } 
      licensed = false; 
      // 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. 
      @SuppressWarnings("unused") 
      String result = String.format(getString(R.string.application_error), errorCode); 
      checkingLicense = false; 
      didCheck = true; 

      //displayResult(result); 
      showDialog(0); 
     } 

     @Override 
     public void allow(int reason) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void dontAllow(int reason) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void applicationError(int errorCode) { 
      // TODO Auto-generated method stub 

     } 
    } 

    protected Dialog onCreateDialog(int id) { 
     // We have only one dialog. 
     return new AlertDialog.Builder(this) 
       .setTitle(R.string.unlicensed_dialog_title) 
       .setMessage(R.string.unlicensed_dialog_body) 
       .setPositiveButton(R.string.buy_button, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
         Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
           "http://market.android.com/details?id=" + getPackageName())); 
         startActivity(marketIntent); 
         finish(); 
        } 
       }) 
       .setNegativeButton(R.string.quit_button, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
         finish(); 
        } 
       }) 

       .setCancelable(false) 
       .setOnKeyListener(new DialogInterface.OnKeyListener(){ 
        public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) { 
         Log.i("License", "Key Listener"); 
         finish(); 
         return true; 
        } 
       }) 
       .create(); 

    } 

답변

0

그럼 내가 마지막으로, 나는 수 무시했다 그것을 알아 냈다()와 dontAllow()가 작동을 받으실 수 있습니다!

관련 문제