Skip to content

Instantly share code, notes, and snippets.

@pboos
Created November 8, 2012 12:37
Show Gist options
  • Save pboos/4038551 to your computer and use it in GitHub Desktop.
Save pboos/4038551 to your computer and use it in GitHub Desktop.
Android: Make your Android apps unlockable through payment
if (isPackageAvailable("ch.pboos.android.SleepTimerPayPal")) {
Intent intent = new Intent(
"ch.pboos.android.SleepTimerPayPal.CHECK");
startActivityForResult(intent, CHECK_PAYMENT);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.unlock);
if(isAppPayed()){
setAppToPayed();
return;
}
if (isPackageAvailable("ch.pboos.android.SleepTimerPayed")) {
setAppToPayed();
return;
}
...
}
private boolean isAppPayed() {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
return settings.getBoolean(getString(R.string.attr_ispayed), false);
}
public boolean isPackageAvailable(String packageName) {
int sigMatch = getPackageManager().checkSignatures(getPackageName(), packageName);
return sigMatch == PackageManager.SIGNATURE_MATCH;
}
protected void setAppToPayed() {
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(getString(R.string.attr_ispayed), true);
editor.commit();
finish();
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if(isAppPayed())
menu.findItem(R.id.menu_unlock).setVisible(false);
return super.onPrepareOptionsMenu(menu);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment