Marshmallow FINE and COARSE location permission - android

I'm trying to access ACCESS_FINE_LOCATION and if it cannot be found access ACCESS_COARSE_LOCATION. So I request for those 2 permission, but they give me the same dialog asking for location permission. I know those are both in the same group but Google says:
Note: Your app still needs to explicitly request every permission it needs, even if the user has already granted another permission in the same group. In addition, the grouping of permissions into groups may change in future Android releases. Your code should not rely on the assumption that particular permissions are or are not in the same group.
This means I ask for those 2 permissions within a second, which results in 2 dialog in a row. THis does not seem very user friendly to me. Is there a better way?

You do not need ACCESS_COARSE_LOCATION permission when you define ACCESS_FINE_LOCATION permission.
From Android Documentation:
Requesting User Permissions
In order to receive location updates from NETWORK_PROVIDER or
GPS_PROVIDER, you must request user permission by declaring either the
ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission,
respectively, in your Android manifest file. For example:
<manifest>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
.......
</manifest>
Without these permissions, your application will fail at runtime when
requesting location updates.
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then
you need to request only the ACCESS_FINE_LOCATION permission, because
it includes permission for both providers. (Permission for
ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)
Please look at https://developer.android.com/guide/topics/location/strategies.html

I have resolved the same problem.Try to give it runtime permission and Firstly check the manifest SDK version and if your version is greater than 6.0 or equal to 6.0 then you need to check permissions for your permission and pass permission Fine location only in request location then definitely it will work.
if you got stuck in code then you may ask for code I will update you but firstly go through these steps.
if you got success to perform your task then rate it.

Related

ACCESS_MEDIA_LOCATION permission request is not showing prompt

I've set my app to target AP 29 and removed requestLegacyExternalStorage=true from manifest.
Now I'm checking if the user has this permission and if result is denied I request for permission.
My problem is that the request for permission is returning Granted without showing the prompt... I know the flow is working since I'm able to read the GPS location from picture after being granted.
I see permission status = Denied and as soon as I explicitly request this permission, it returns Granted without any user interaction.
Eveything looks OK but I'm confused about not seeing the prompt... is this expected? I saw this permission qualifies as "Dangerous" so I was expecting a prompt. I'm testing on a Android 10 device.
I'm not showing any code since the project is Xamarin and the permission logic is handled through a third party library, don't think my code will help as the platform logic to request the permission is hidden by the component.
From
Android 10: fetch the gallery via MediaStore with location information :
This requires holding the ACCESS_MEDIA_LOCATION permission. Note, this permission is not "user visible in the settings UI" (source), which means the user won't see a popup asking for permission, even though it is a runtime permission. This means you have to ask for permission during runtime (in contrast to just the manifest file) but the user won't have to consent to it. Adding this here because you might be wondering why no extra UI popups are shown.
I'm still getting my head around the logic though. I'm in favour of the user being asked for permission but I don't understand why it should be necessary to "request" it if the user doesn't actually grant permission.
I was able to reproduce the issue in a simpler app. I have posted a slightly different question with code snippets.
This is an answer by HilaryN that I believe should not have been deleted (I removed the off-topic bits).

Can Android normal level permissions be requested at installation time (in the manifest)?

In later versions of Android (like 8.0.0), can we still declare normal level permissions in the manifest, like INTERNET permission and expect it to be granted at installation time?
<uses-permission android:name="android.permission.INTERNET" />
or do we need to explicitly request them through the code?
If the second, do we need to ask for it on every single activity?
can we still declare normal level permissions in the manifest, like INTERNET permission and expect it to be granted at installation time?
Yes. Only dangerous ones need to be requested at runtime.
Yes, you can declare normal level permissions in the manifest. But in 6.0 and above you have to check that permission is granted or not by user at runtime.

Right way of requesting storage permission in android 6

While requesting storage permissions in android 6, Is it better to -
1) ask for both READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE through activity?
2) specify both android.permission.READ_EXTERNAL_STORAGE and android.permission.WRITE_EXTERNAL_STORAGE in manifest?
I noticed that by requesting only read permission, the storage permissions toggle button gets toggled, so technically I am getting both by asking for just one.
You always have to request permissions through the manifest. Whether you also have to request them via requestPermissions() depends on OS version and your targetSdkVersion.
I noticed that by requesting only read permission, the storage permissions toggle button gets toggled, so technically I am getting both by asking for just one.
At present, while we request permissions, users grant permission groups. That may change in the future.

MarshMallow Permission for gmaps

If gmaps needs this permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
should I ask for each one to the user with requestPermissions ?
I checked some times and it only crash saying that the user didnt give permissions for android.permission.ACCESS_FINE_LOCATIONbut not the others, why?
should I ask for each one to the user with requestPermissions ?
First when to use requestPermission ?
requestPermission is only call after checkSelfPermission when this method doesn't return PERMISSION_GRANTED.
You can find a list of permission that android M requires during the runtime. Each of these Permissions are part of a Permission group. WRITE_EXTERNAL_PERMISSION is from android.permission-group.STORAGE and ACCESS_COARSE_LOCATION / ACCESS_FINE_LOCATION are from android.permission-group.LOCATION.
If the user allows the access to a permission -for example ACCESS_COARSE_LOCATION-, then android will automatically grant the access of this permission group -i.e. permission-group.LOCATION-. So if you later checkSelfPermission for ACCESS_FINE_LOCATION, you should receive PackageManager.PERMISSION_GRANTED.
If you app crashes, it means that you tried to call, for example LocationServices.FusedLocationApi.requestLocationUpdates before requesting from the user the permission-group Location.
Edit:
Do not forget that requestPermission is asynchronous. So do not call a method that requires a permission right after requestPermission. To call a method that requires a permission, you should override onRequestPermissionsResult that give you a list of permission and their state -granted/denied-.
You should only need to request permission for the LOCATION and STORAGE groups. I'm also pretty sure Fine location includes permission for Coarse, so you don't need to include that line in your manifest.

Grant permission required for EXTERNAL_STORAGE in Android M?

Will the Android permissions WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE trigger the new grant permission dialog of Android M?
I agree with Guillaume Perrot 's answer. I have met the similar question when I write the permission of READ_WRITE_EXTERNAL_STORAGE in AndroidManifest.xml
with no permissions showing up in the app by default , people need to switch the toggle button of storage in the app permissions.Then I modify my targetSdkVersion in build.gradle to less than 23(MNC) and other number related with sdkVersion, the app installed with the permissions on.
The other way is to write requestpermission function in the place that you need the permisson. The code is as follow:
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)==
PackageManager.PERMISSION_GRANTED) {
//do the things} else {
requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
AnyNumber);
Because I have less than 15 reputation so I can't vote for the Guillaume Perrot 's answer.Just use this way to show my idea.
I solved add this if check version for Android M
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
}
My answer is based on my tests on M Preview SDK version 2, using an emulator.
If you target MNC preview API level, WRITE_EXTERNAL_STORAGE is not granted by default and will be part of the new dynamic permission API.
You will see the storage permission as a toggle button in the new app permissions menu in device settings, and you can use Activity.requestPermissions to show the popup for that permission.
However if you target api level < MNC, it won't be classified as a dangerous permission, and thus will be granted without a way for the user to disable it (not showing up in permission settings), and you will not be able to compile code using Activity.requestPermissions anyway as the preview SDK enforces minSdkVersion="MNC" to use the new APIs.
This is a different behavior than location permissions: whatever the API level you target, the user will be able to turn location off in permission menu.
For the permission menu itself, the permission toggle state is ON by default if:
Target API level < MNC.
Target API level = MNC but you upgrade app on device from a previous install where target API level was less than MNC.
Otherwise you will see the toggle as OFF by default.
Hope it helps.
According to the docs:
Limited Permissions Granted at Install Time: When the user installs or updates the app, the system grants the app all permissions that the app requests that fall under PROTECTION_NORMAL.
So because READ_EXTERNAL_STORAGE is falling under PROTECTION_NORMAL , it won't trigger the dialog.
But because the level of WRITE_EXTERNAL_STORAGE is PROTECTION_DANGEROUS, it will fall under this behavior as described in docs:
User Grants Permissions at Run-Time: When the app requests a permission, the system shows a dialog to the user, then calls the app's callback function to notify it whether the permission was granted. If a user grants a permission, the app is given all permissions in that permission's functional area that were declared in the app manifest
Here is the sources for the protection level:
detailed list
According to Android docs you don't need to request permission about read and write external storage.
Edit: in the latest Android M release you need to ask for both read and write permissions
Storage permission falls under dangerous protection level, So all the dangerous protection level permissions will not be granted at install time in Android M, if App target SDK is set to 23. They will be given at run time.
And yes these permissions can be revoked at run time also.
No permission dialog will not be triggered automatically, you need to do a request by using API such as requestPermissions() method to show that native dialog.
Please check the dangerous level permission list here

Categories

Resources