package com.your.package; 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.util.Log; 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 Splash extends Activity { private LicenseChecker mChecker; private LicenseCheckerCallback mLicenseCheckerCallback; private static final String BASE64_PUBLIC_KEY = "Copy from developer account"; // Generate 20 random bytes, and put them here. private static final byte[] SALT = new byte[] { -20, 30, 50, -70, 33, -100, 32, -90, -88, 104, 12, -10, 72, -34, 115, 21, 62, 35, -12, 97 }; private AESObfuscator mObsfuscator; private String android_id; /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.splash); android_id = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID); mObsfuscator = new AESObfuscator(SALT, getPackageName(), android_id); ServerManagedPolicy serverPolicy = new ServerManagedPolicy(this,mObsfuscator); mLicenseCheckerCallback = new MyLicenseCheckerCallback(); mChecker = new LicenseChecker( this, serverPolicy, BASE64_PUBLIC_KEY // Your public licensing key. ); mChecker.checkAccess(mLicenseCheckerCallback); } private class MyLicenseCheckerCallback implements LicenseCheckerCallback { public void allow() { if (isFinishing()) { // Don't update UI if Activity is finishing. return; } // Should allow user access. Log.w("LicenseChecker", "Allow"); Intent i = new Intent(Splash.this, Main.class); startActivity(i); finish(); } public void dontAllow() { if (isFinishing()) { // Don't update UI if Activity is finishing. return; } Log.w("LicenseChecker", "Don't Allow"); // Should not allow access. An app can handle as needed, // typically by informing the user that the app is not licensed // and then shutting down the app or limiting the user to a // restricted set of features. // In this example, we show a dialog that takes the user to Market. showDialog(0); } @Override public void applicationError(ApplicationErrorCode errorCode) { if (isFinishing()) { // Don't update UI if Activity is finishing. return; } toast("Error: " + errorCode.name()); } } @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 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("market://details?id=" + getPackageName())); startActivity(marketIntent); finish(); } }) .setNegativeButton("Exit", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }).create(); } public void toast(String string) { Toast.makeText(this, string, Toast.LENGTH_SHORT).show(); } @Override protected void onDestroy() { super.onDestroy(); mChecker.onDestroy(); } }