For Android Lollipop and below versions I am checking like below.
if (Secure.getString(this.cordova.getActivity().getContentResolver(), Secure.ALLOW_MOCK_LOCATION).equals("0")) {
return true;
} else {
return false;
}
But for Android M this option is removed. Right now for Android M I am doing Like below. But this is not working and throwing an exception.
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
AppOpsManager opsManager = (AppOpsManager) this.cordova.getActivity().getApplicationContext().getSystemService(Context.APP_OPS_SERVICE);
PackageManager pm = this.cordova.getActivity().getApplicationContext().getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : packages) {
if (opsManager.checkOp(AppOpsManager.OPSTR_MOCK_LOCATION, applicationInfo.uid, applicationInfo.packageName)== AppOpsManager.MODE_ALLOWED) {
return true;
break;
}
}
}
To Solve this issue I've read all the below links but nothing is satisfying my Requirement. My Requiremnet is, If any of the app set to use Mock Location then I should get the true. Based on that I will notify the user to set the option nothing