Skip to content

Instantly share code, notes, and snippets.

@Minishlink
Created August 1, 2019 08:18
Show Gist options
  • Save Minishlink/69b58caec55efeef42d39c225eb714e4 to your computer and use it in GitHub Desktop.
Save Minishlink/69b58caec55efeef42d39c225eb714e4 to your computer and use it in GitHub Desktop.
RootBeer example
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
if (!BuildConfig.DEBUG && !BuildConfig.SKIP_ROOT_CHECK) {
RootBeer rootBeer = new RootBeer(this);
if (rootBeer.isRootedWithoutBusyBoxCheck()) { // isRooted has false positives (OnePlus devices and MotoE)
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("You cannot use this app on a rooted device.")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
exitApp();
}
})
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
exitApp();
}
})
.show();
}
}
super.onCreate(savedInstanceState);
}
private void exitApp()
{
if (Build.VERSION.SDK_INT >= 21) {
finishAndRemoveTask();
} else {
finish();
}
System.exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment