2013-04-23 108 views
6

我实现了谷歌的许可cheker通过阅读the official instructionsAndroid授权应用程序无效?

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(); 
    } 
} 

,这里是我实现这个我在运行应用程序,并与释放钥匙签署,并在谷歌Play开发者控制台上传的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个测试帐户。

按照我阅读并理解必须在具有测试帐户作为它会显示在对话框对该设备的设备和休息主帐户关联的设备上运行。

但在我的情况下,在所有设备中它会正常工作,如果互联网断开,这件事情会发生一些奇怪的情况,而不是显示关于盗版的对话,并且如果连接比它在所有设备中都好看, 。

回答

1

最后我找到了正确的方式来测试谷歌许可证检查。

正如我上载的APK在谷歌Play开发者控制台为草稿和 如果我安装APK在任何设备比它会与如果设备不具有测试账号登陆许可响应运行。

最后我做测试这样我加入的测试帐号,我选择为许可比应用程序将运行在开发者控制台许可测试响应后,我又在开发者控制台与NOT_LICENSED比它显示更改设置以测试账户为主要账户的设备中的盗版对话。

重要提示:等相比测试帐户的设备将其与特许经营怎么一回事,因为是我上传的APK如草案中发挥store.So的测试谷歌的许可,我们必须要考虑加入唯一的测试帐号的响应运行谷歌Play开发者控制台

+0

它不适合我....请帮助我。我按照你所说的做了,但每次盗版对话弹出 – user2592807 2014-06-28 16:21:27

+0

你必须在谷歌播放开发者控制台添加测试Gmail帐户,并在设备中,你必须有该帐户作为主要的Gmail帐户,用于从Play商店下载应用程序。就像我提到的许可测试响应一样,您需要选择LICENSED而不是NOTLICENSED或任何其他选项。 – Khan 2014-06-30 05:34:08

+0

我不断收到错误,“错误:(48,0)com.android.vending.CHECK_LICENSE描述无效”。任何机会有人知道为什么?非常感谢。 – cjayem13 2014-11-25 20:08:46

0

的LVL正在与你加入,不仅主帐户的帐户的所有设备。它不应该在手机上使用帐户您不添加到开发者控制台。即使LVL试图验证你的应用程序与谷歌LVL服务器,所以你需要一个互联网连接,这是好的。如果你只是想检查一次许可证,你必须保存在共享偏好,例如一些数据,该检查已经完成。因此,下次应用程序启动时,您可以检查这些保存的共享首选项,如果该应用程序刚刚被验证。如果是,请不要再检查,如果不是,请再试一次。

您可以在开发者控制台检查许可证的行为,你可以模拟一个正常的反应,或者例如“未验证”响应等等....

+0

在我的情况下,它也能在其帐户我还没有在开发者控制台添加意味着应用程序工作在所有设备 – Khan 2013-04-23 13:02:43

+0

好设备,比我确实理解错了。您真的确定在另一台设备上没有测试帐户吗?我的意思是,可以有多个帐户,也许这个设备上也有测试帐户? – Opiatefuchs 2013-04-23 13:16:29

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.