Last active
July 11, 2020 07:52
-
-
Save MrCrambo/a682260a97121472415c34d7bae76293 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 (!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