title: Android licensing application not works?
body: <p>I implemented Google License checker by reading <a href="http://developer.android.com/google/play/licensing/index.html" rel="nofollow noreferrer">the official instructions</a>.</p>
  
  <pre><code>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();
      }
  }
  </code></pre>
  
  <p>and here is the manifest permission which I given</p>
  
  <pre><code>&lt;supports-screens android:normalScreens="true" android:largeScreens="true" android:smallScreens="true" android:anyDensity="true" android:xlargeScreens="true" android:resizeable="true"/&gt;
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  &lt;uses-permission android:name="com.android.vending.CHECK_LICENSE" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
  &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  </code></pre>
  
  <p>after implementing this I run app in and sign it with with release key and uploaded apk as draft in <strong>google play developer console</strong>  and I have also added 3 test account in setting of developer console.</p>
  
  <p>As per I read and understand the must be run in the device which having the test account as main account in device and rest of the device it would have to show the dialog.</p>
  
  <p>But in my case in all device it will works fine and this thing happen some strange situation if internet is disconnected than it will show dialog about piracy and if it is connected than it worsk in all device inspite of the test account devices.</p>