2012-01-14 4 views
3

앱이 있으며 저작권 보호 도구 대신 Google 라이센스를 추가하려고합니다.서버/서비스가없는 상태에서 Android 라이센스 확인 가능

내 문제는 : 장치가 연결할 수 있으면 문제가 없으며 라이센스가 있으면 액세스가 허용됩니다. 장치가 연결할 수 있고 라이센스가없는 경우 액세스가 거부됩니다.

하지만 비행기 모드, 데드 존 등으로 인해 기기를 연결할 수없는 경우 앱에서 허가되지 않은 응답을 제공합니다.

여기 내 코드 : 패키지 "패키지 이름";

import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Dialog; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.provider.Settings.Secure; 
import android.widget.Toast; 

import com.android.vending.licensing.AESObfuscator; 
import com.android.vending.licensing.LicenseChecker; 
import com.android.vending.licensing.LicenseCheckerCallback; 
import com.android.vending.licensing.ServerManagedPolicy; 


public class LicenseCheck extends Activity { 
    private class MyLicenseCheckerCallback implements LicenseCheckerCallback { 

     @Override 
     public void allow() { 
      if (isFinishing()) { 
       // Don't update UI if Activity is finishing. 
       return; 
      } 
      // Should allow user access. 
      startMainActivity(); 

     } 


     @Override 
     public void applicationError(ApplicationErrorCode errorCode) { 
      if (isFinishing()) { 
       // Don't update UI if Activity is finishing. 
       return; 
      } 
      // 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. 
      toast("Error: " + errorCode.name()); 
      startMainActivity(); 

     } 

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

      // 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. 
      showDialog(0); 
     } 
    } 



    private static final String BASE64_PUBLIC_KEY =  "MY KEY"; 

private static final byte[] SALT = new byte[] { "20 RANDOM INTEGERS" }; 
private LicenseChecker mChecker; 

// A handler on the UI thread. 

private LicenseCheckerCallback mLicenseCheckerCallback; 

private void doCheck() { 

    mChecker.checkAccess(mLicenseCheckerCallback); 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

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

} 

@Override 
protected Dialog onCreateDialog(int id) { 
    // We have only one dialog. 
    return new AlertDialog.Builder(this) 
      .setTitle("Application Not Licensed") 
      .setCancelable(false) 
      .setMessage(
        "This application is not licensed. Please purchase it from the Android Market") 
      .setPositiveButton("Buy App", 
        new DialogInterface.OnClickListener() { 
         @Override 
         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("Exit", 
        new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, 
           int which) { 
          finish(); 
         } 
        }).create(); 
} 

@Override 
protected void onDestroy() { 
    super.onDestroy(); 
    mChecker.onDestroy(); 
} 

private void startMainActivity() { 
    startActivity(new Intent(this, MY_Activity.class)); 
    finish(); 
} 

public void toast(String string) { 
    Toast.makeText(this, string, Toast.LENGTH_SHORT).show(); 
} 

} 

NO 라이센스 만 제공되면 액세스를 차단할 의지도 있습니다. 앱을 실행하고 서버를 사용할 때마다 확인하는 편이 낫습니다. 서버에 연결할 수 있는지 확인하기 위해 검사를 실행할 수 있다고하더라도.

답변

1

해결 방법이 있습니다. 나는 해결책을 찾지 못했습니다. 철저한 조사를 거친 후, 기본적으로 연결이 없거나 비행기 모드에있는 경우 라이선스 검사는 자동으로 NOT_LICENSED가 기본값임을 알게되었습니다.

연결을 확인한 것입니다. 연결이 있으면 라이센스 검사를 실행합니다. 연결이 없으면 주 활동으로 넘어갑니다.

1

아마도 LVL 라이브러리와 함께 테스트 계정을 사용하고있을 것입니다. Google Test 계정을 사용하는 경우 라이센스는 1 분 동안 만 유효하며, 분이 지나면 추가 라이센스 확인시 유효한 응답을 얻기 위해 넷 액세스가 필요합니다. 앱을 구입 한 실제 계정으로 유효한 라이선스 응답이 며칠 동안 캐시됩니다 (ServerManagedPolicy를 사용한다고 가정).

0
public void dontAllow(int policyReason) { 

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

    if (policyReason == Policy.RETRY) { 
     //-- no connection (unable to validate license). 
    } else { 
     //-- no license (application is not licensed). 
    } 

    showDialog(0); 
}