Skip to content

Instantly share code, notes, and snippets.

@MrCrambo
Last active July 11, 2020 07:52
Show Gist options
  • Save MrCrambo/a682260a97121472415c34d7bae76293 to your computer and use it in GitHub Desktop.
Save MrCrambo/a682260a97121472415c34d7bae76293 to your computer and use it in GitHub Desktop.
...
if (!isMockLocationEnabled)
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
...
private boolean isMockLocationEnabled()
{
boolean isMockLocation;
try {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
AppOpsManager opsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
isMockLocation = (Objects.requireNonNull(opsManager).checkOp(AppOpsManager.OPSTR_MOCK_LOCATION, android.os.Process.myUid(), BuildConfig.APPLICATION_ID)== AppOpsManager.MODE_ALLOWED);
} else {
isMockLocation = !android.provider.Settings.Secure.getString(mContext.getContentResolver(), "mock_location").equals("0");
}
} catch (Exception e) {
return false;
}
return isMockLocation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment