I'm using a rooted M device and trying to access the permissions setting for other apps.
I would like to know which permissions are granted or revoked by user for each app
can this be available?
can checkSelfPermission() work for that?
Also, if I'm downloading an app which is not developed for M version can the detection operation work or not because I found that any app whit target version lower than 23 will always return PERMISSION_GRANTED
checkSelfPermission returning PERMISSION_GRANTED for revoked permission with targetSdkVersion <= 22
Related
I'm using altbeacon library to monitor and range beacons. I've read your requesting permission page and just want to know, if I target location permission for API 23+ (), will scan works on devices with API < 23? I don't have real device, so can't test it. Or is there any way to not request location permission with device with API below 23? Thanks for your answers
Restating the core question:
If you build an app that has a minSdkVersion < 23 but the targetSdkVersion >= 23, what happens when you try to scan for bluetooth beacons?
Short answer: it works.
Longer answer:
The user permissions request won't happen. with a minSdkVersion < 23, The compiler will stop you from including a line of code like requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);
because it won't run on earlier Android versions. If you wrap it in an if statement like if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) it won't get executed. If you add annotations like #SuppressLint("NewApi") the app will crash when trying to execute the code.
The beacon scanning will just work, both in the foreground and the background, regardless of the fact that the user permissions have not been granted. Earlier Android versions can't request the permission from the user, so the app just behaves as if they have been granted.
On Android 23 and on, you need to check if the app has been granted a "dangerous" permission and if not ask the user.
The Android support library has helper functions for this.
See Requesting Permissions at Run Time.
The main functions are checkSelfPermission and requestPermissions.
In order not to have problems with older versions of Android you can use the following to check if you are on a device running Marshmallow or not:
public static boolean isMNC() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
This will return true if you are on a device running Marshmallow or newer, false otherwise. So, if this returns true, check for the permission, otherwise don't.
You should probably also use the annotation #SuppressLint("NewApi") on the function where you call the checkSelfPermission and requestPermissions.
As we know in Marshmallow we need to ask permission from users.
Recently I have installed BookMyShow and found there is no dialog pop up for permission.
When I checked from setting->app, All required permissions were there.
how do they do it? ..
Their targetSdkVersion is lower than 23, presumably.
So I have camera permission in manifest , Still when app goes to start camera it crashes .this happens beacuse user had denied the permission in permission manager for camera that comes with xiaomi devices
So the app Crashes , can someone help about how to handle this.
with the normal way of getting permisions , it does not give correct result
String permission = "android.permission.CAMERA";
int res = getContext().checkCallingOrSelfPermission(permission);
res is always 0(has Permission) for below 23 devices , if user has manually denied permission by going to permission manager then also
Revoking permissions on android devices below 23 is non-standard behavior and is afaik only possible through customized OS versions (like Cyanogen mod or in your case, the Xiaomi modified version). Users should be aware, that revoking permissions that way may cause error ins apps.
Prior to Android 6.0, you could reasonably assume that if your app is running at all, it has all the permissions it declares in the app manifest.
https://developer.android.com/training/permissions/best-practices.html#testing
Therefore I suggest you run your methods that require a certain permission with a try/catch. If the api lvl is below 23 and your method call fails, you know for sure if you have the permission or not.
After further research, i found that requestPermission only works on Android M. If i just include the permissions i needed in android manifest file, how does android ask user for the permission granted? For example, access fine location permission. I try including the requestPermission but never see the dialog.
Before Marshmallow, all the permissions are granted at installation time. That's why you don't see a dialog requesting permission on Lollipop and previous versions on runtime.
Check this out: Runtime Permissions. It only applies to Marshmallow and above.
I am trying to check for permissions being granted/revoked by user in Android Marshmallow. Unfortunately ContextCompat.checkSelfPermission() (which is a warpper around Context.checkCallingOrSelfPermission) seems to always return PackageManager.PERMISSION_GRANTED (0) if you have included that specific permission in your manifest regardless of the current state of the permission (e.g. if the user has revoked the permission). I also tried someContext.checkCallingOrSelfPermission(), but the result is the same.
Has anyone experienced this? I am using Android Marshmallow on nVidia Shield console (using nVidia's Beta program).
As it turns out, The targetSdkVersion in the manifest must be 23, mine was 22. If your target SDK is 23 (Android 6), all of the permissions (in your manifest) are disabled by default, whereas if your target SDK is 22 (Android 5.1) and your app is running on Android 6, all of the permissions are enabled by default when the user installs the app, and even if the user revokes the permissions later on, the mentioned API returns incorrect value (which is a bug in my opinion).