Skip to content

Instantly share code, notes, and snippets.

@chrislacy
Created August 22, 2014 00:16
Show Gist options
  • Save chrislacy/4e373420f1c1b74aa481 to your computer and use it in GitHub Desktop.
Save chrislacy/4e373420f1c1b74aa481 to your computer and use it in GitHub Desktop.
Disabling Activity (after verifying purchase)
try {
ComponentName componentName = new ComponentName(getPackageName(), YourActivity.class.getName());
PackageManager packageManager = getApplicationContext().getPackageManager();
if (licenseState == LICENSE_VALID) {
if (packageManager.getComponentEnabledSetting(componentName) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
} else if (licenseState == LICENSE_INVALID) {
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}
} catch (Exception ex) {
// Be sure to trap any and all potential issues with the above code.
// It's not critical that it succeeds.
Log.d(TAG, "Disabling component failed", ex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment