2013-04-23 2 views
6

the official instructions을 읽음으로써 Google License cheker를 구현했습니다. 여기Android 라이선스 애플리케이션이 작동하지 않습니까?

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

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

public class Splash extends Activity { 
    MyLicenseCheckerCallback mLicenseCheckerCallback; 
    LicenseChecker mChecker; 
    byte[] SALT = new byte[] { -73, 95, 70, -126, -103, -57, 14, -46, 51, 88, -5, 
     -60, 77, -88, -63, -13, -1, 82, -4, 9 }; 
    //Handler mHandler; 
    String BASE64_PUBLIC_KEY="My base key"; 
    Context mContext; 
    IBinder serviceBinder; 
    String deviceId; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 

     mLicenseCheckerCallback = new MyLicenseCheckerCallback(); 
     deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID); 
     // Construct the LicenseChecker with a policy. 
     mChecker = new LicenseChecker(this, 
      new ServerManagedPolicy(Splash.this, new AESObfuscator(SALT, 
       getPackageName(), deviceId)), BASE64_PUBLIC_KEY); 
     doCheck(); 
    } 

    private class MyLicenseCheckerCallback implements LicenseCheckerCallback { 
     @Override 
     public void allow(int reason) { 
      // TODO Auto-generated method stub 
      if (isFinishing()) 
       return; // Don't update UI if Activity is finishing. 
      // Toast.makeText(Splash.this, "Success", Toast.LENGTH_LONG).show(); 
      Intent intent=new Intent(Splash.this,Main.class); 
      startActivity(intent); 
      finish(); 

      // Should allow user access. 
      // so do nothing 
     } 

     @Override 
     public void dontAllow(int reason) { 
      // TODO Auto-generated method stub 
      if (isFinishing()) 
       return; // Don't update UI if Activity is finishing. 
      // Toast.makeText(Splash.this, "Fail", Toast.LENGTH_LONG).show(); 
      createDialog(); 
     } 

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

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

    private void doCheck() { 
     // mCheckLicenseButton.setEnabled(false); 
     setProgressBarIndeterminateVisibility(true); 
     /// mStatusText.setText(R.string.checking_license); 
     mChecker.checkAccess(mLicenseCheckerCallback); 
    } 

    public void createDialog(){ 
     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setTitle("PIRACY WARNING"); 
     builder.setMessage("A valid purchase for My App has not been detected. Your IP" 
      + " has been logged and all offenders will be reported to the authorities." 
      + " If you received this message in error, please contact Support."); 
     builder.setPositiveButton("Buy Now", 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); 
      } 
     }); 
     builder.setNegativeButton("Quit", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 
       finish(); 
      } 
     }); 
     AlertDialog dialog = builder.create(); 
     dialog.show(); 
    } 
} 

와 내가에서 응용 프로그램을 실행하고 릴리스 키와 서명 및 구글 플레이 개발자 콘솔에서 초안으로 APK를 업로드하고이를 구현 한 후

<supports-screens android:normalScreens="true" android:largeScreens="true" android:smallScreens="true" android:anyDensity="true" android:xlargeScreens="true" android:resizeable="true"/> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<uses-permission android:name="com.android.vending.CHECK_LICENSE" /> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

주어진 menifest 권한입니다 또한 개발자 콘솔 설정에 3 가지 테스트 계정을 추가했습니다.

필자는 테스트 계정을 장치의 메인 계정으로 사용하고 장치의 나머지 부분이 대화 상자를 표시해야하는 장치에서 실행되어야 함을 알고 있습니다.

내 경우에는 잘 작동하지만 인터넷 연결이 끊어지면이 이상한 상황이 발생하여 불법 복제에 관한 대화 상자가 표시되고 모든 장치에 문제가있는 것보다 연결되어있는 경우 테스트 계정 devies .

답변

1

마지막으로 Google 라이센스 검사기의 적절한 테스트 방법을 발견했습니다. 이 장치에서 테스트 계정으로 로그인을 가지고 있지 않은 경우으로 허가 응답 으로 실행됩니다보다

내가 구글에서 APK를 초안으로 Play 개발자 콘솔 업로드로하고 나는 모든 장치에서 그 APK를 설치하는 경우.

그리고 마지막으로 나는이 방법을 테스트 할 내가 테스트 계정을 추가하고 난 실행 응용 프로그램에 비해 라이선스 로 개발자 콘솔에서 라이센스 테스트 응답를 선택하고 보여줍니다보다 나는 또한 NOT_LICENSED와 개발자 콘솔에서 설정을 변경 한 후 테스트 계정을 메인 계정으로 갖는 장치의 불법 복제에 관한 대화 상자.

중요 참고 : 테스트 계정 디바이스보다 그리고 다른 하나는이 beacuse가 나는 우리는 테스트 계정에 추가 고려해야하는 데 필요한 테스트 구글 라이센스에 대한 플레이 store.So에서 초안으로 APK를 업로드 라이선스 응답 실행 Google Play 개발자 콘솔

+0

그게 나를 위해 일하지 않는다 .... 나를 도와주세요. 내가 언급했듯이 해적판 다이얼로그가 팝업 될 때마다 – user2592807

+0

Google Play 개발자 콘솔에 테스트 Gmail 계정을 추가해야하며 기기에서 Play 계정에서 앱을 다운로드하는 데 사용되는 메인 Gmail 계정으로 계정을 보유해야합니다. 물론 라이센스 테스트 응답에서 언급 한 바와 같이 라이센스가 부여되지 않았거나 다른 옵션 대신 라이센스를 선택해야합니다. – Khan

+0

계속해서 오류가 발생합니다 : "오류 : (48, 0) 설명 com.android.vending.CHECK_LICENSE가 유효하지 않습니다." 어떤 사람이 이유를 아는가? 많은 감사합니다. – cjayem13

0

LVL은 기본 계정뿐만 아니라 추가 한 계정으로 모든 장치에서 작동합니다. 계정이있는 휴대 전화에서는 작동하지 않아야합니다. 개발자 콘솔에 추가하지 않았습니다. 심지어 LVL은 Google LVL - 서버로 앱을 인증하려고하므로 인터넷 연결이 필요합니다. 괜찮습니다. 라이센스를 한 번만 확인하려면 공유 환경 설정에 일부 데이터 (예 : 수표가 이미 저장되어 있음)를 저장해야합니다. 따라서 다음에 앱이 시작될 때 앱이 방금 확인되면 저장된 공유 환경 설정으로 확인할 수 있습니다. 예이면 다시 확인하지 않으시 고 다시 시도하십시오. u는 이미 모든 단계를 완료

+0

제 경우에 개발자 콘솔에 계정이 추가되지 않은 기기에서도 작동합니다. 앱이 모든 기기에서 작동하고 있음을 의미합니다. – Khan

+0

오케이, 잘못 이해합니다. 정말로 다른 기기에서는 테스트 계정이 없다고 확신하십니까?내 말은, 하나 이상의 계정을 가질 수 있으며이 장치에도 테스트 계정이있을 수 있습니까? – Opiatefuchs

1

당신은 개발자 콘솔에서 라이센스를 확인하는 동작을 설정할 수 있습니다

는 .... 등등, 당신은 정상 응답을 시뮬레이션 할 수 있습니다, 또는 예를 들어 "확인되지"응답 하지만 다시 한 번 명확하게 확인하십시오.

1.check once ur's public key compare with the draft store public key. 
2.Give own salt 20 numbers. 
3.Give properly test accounts in the google play and same account 
    use in the device also. 
4.In google play u have to put licensed mode for application draft. 
5.check after some time because it will take some time to give valid results. 
6.finally verify the alert dialog conditions in application. 
7.clear the google play cache in ur mobile may be it will store the results. 
관련 문제