Created
November 8, 2012 12:37
-
-
Save pboos/4038551 to your computer and use it in GitHub Desktop.
Android: Make your Android apps unlockable through payment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (isPackageAvailable("ch.pboos.android.SleepTimerPayPal")) { | |
Intent intent = new Intent( | |
"ch.pboos.android.SleepTimerPayPal.CHECK"); | |
startActivityForResult(intent, CHECK_PAYMENT); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment