how to check whether a permission is denied by user in android - android

for example,my app requests a permission in Manifest file,like android.permission.WRITE_EXTERNAL_STORAGE,how can i check whether the permission is denied by user or some security apps?

Call context.checkCallingPermission(permission)
permission -- The name of the permission being checked, as a String
Returns PERMISSION_GRANTED if you have the permission, or PERMISSION_DENIED if not.
See checkCallingPermission
As noted in the docs and the comments, there are some subtleties here.

Right now, android asks for the user to accept all the permissions an app asks for in the manifest on installation. In the upcoming M release, android will switch over to the iOS style of permissions with an "on needed" basis. (For certain permissions. See #Commonsware's comment for more details) Meaning whenever the user tries to use a feature that requires permission it will ask them to accept or deny. If they hit deny I imagine there will be an sdk positive and negative response button interface to implement.
As for right now in your dilemma, if the user rejects permissions they won't be able to use your app period.

You can use checkCallingPermission() to check weather the runningtime permission is denied by users or some apps.

Related

Enabling phone permissions without alerting the user to enable during runtime in Xamarin forms

I want to enable phone permission by default for an Android application. On checking multiple posts I see that it is getting added up at runtime explicitly by user during installation. Can I avoid it and enable it by default?
I am adding the permission READ_PHONE_STATE in Android Manifest. But this doesn't enable it by default unless and until the user goes to the setting and enable it manually.
Permission needs to be requested from the user. If you try to use the feature without permission, it will crash the app. The permission needs to be in the manifest and you need to request permission from the user as well. There is no way to do it automatically.
Side note: I believe this permission specifically is under higher scrutiny when submitted to the Play Store. The announcement they sent last year mentioned that you'll only be able to use this permission if you provide a valid reason such as making an alternative dialer app.

Getting reviewed applications' permissions on android M+

I'm currently studying the new permissions' system from Android (M and over). I need to find a way to see what permissions from all apps have been already consented by the user. For example, if a permission belongs to the dangerous protection level, I need to know if the user was already prompted with the accept/deny dialog (note that I know if that permission is currently denied or granted).
For now, I've discovered that if a permission has a dangerous protection level and it is currently granted, that means that the user has already consented to this permission (since denied is the default on the dangerous level). But if the permission is currently denied, the user may have decided to deny the permission or it may still be the default value (permission was not yet used/prompted to the user). Similarly, if the permission is from the normal protection level and it is currently denied, then the user explicitly denied this permission (since the default is granted). And so on for the other groups.
To sum up what I'm asking: I have access to all packages and all granted and denied permissions. What I want to know is if I have a way to know if the packages' permissions are consented by the user or if it is still the default value.
Thank you very much for any help. Let me know if you need any code or any further explanation.

Handling Android M run-time permissions with multi module project

I have a multiple module Android M app. Several modules require "WRITE_EXTERNAL_STORAGE" & "READ_EXTERNAL_STORAGE" permissions.
I would like to ask the user for permissions once:
1. Where would be the right place to do that?
1.1 Are permissions granted per activity?
1.2 Would asking for permission in module 1 give permissions to all app?
1.3 Is there a way to ask for both READ & WRITE permissions?
Google has published guidelines describing when to ask for permissions. It depends on context. Your questions 1.1 and 1.2 can be answered with the same info: permissions are granted and denied at the app level. It applies to every part of your app package. For 1.3: they are limited together into a group. When you ask for one you automatically get everything in the group.
This talk from DroidconNYC NYC will give you more details: https://youtu.be/WGz-alwVh8A.
Where would be the right place to do that?
From somewhere in your UI, before you need those permissions.
Are permissions granted per activity?
No, they are for the entire application.
Would asking for permission in module 1 give permissions to all app?
Asking for a permission in a module will give that permission to the entire app, if the user grants you the permission.
Is there a way to ask for both READ & WRITE permissions?
In this case, AFAIK you do not need both. Just ask for WRITE_EXTERNAL_STORAGE. In general, you can request as many permissions as you want; the requestPermissions() method takes a String[] of permission names.

Please explain Android permission protection_signature explanation

I got the below explanation from Android documentation, about the new permission model in Android M Preview. Please explain the texts in bold in simple words because I am confused.
If the app requests permissions in the manifest that fall under PROTECTION_SIGNATURE, and the app is signed with the same certificate as the app that declared those permissions, the system grants the requesting app those permissions on installation. Apps cannot request signature permissions at runtime.
Apps can define their own permissions via the manifest. This is referring to those permissions. So if I publish 2 apps, both signed with the same certificate, and app#1 defines a new permission with signature level protection and app#2 uses that permission (by stating so in its manifest) then the system will automatically grant the permission to app#2. Note that this is not new to Android Marshmallow. Only the selective grant/revoke is.
This article will help to explain permissions in general under Android: http://hiqes.com/android-security-part-2
Let me guess.
there are two apps, A and B, they was signed with the same certificate.
first at all, user start using A app, and request permissions EXAMPLE_PERMISSION under PROTECTION_SIGNATURE, then system gives a dialog and tips user that he need to grant it. user click GRANT.
And then, user launch B app, B app wants the same permission, the EXAMPLE_PERMISSION, and when it requests the permission, system auto grant that.
Because of A app has granted it, and A and B have the same certificate.
I guess so.

INTERNET permissions in Android M

Regarding Google's recent announcement about Android M and Permissions model.
Per the official Android documentation:
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. For example, alarm
clock and internet permissions fall under PROTECTION_NORMAL, so they
are automatically granted at install time. The system may also grant
the app signature and system permissions, as described in System apps
and signature permissions. The user is not prompted to grant any
permissions at install time.
Particular note that it says:
...the system grants the app all permissions that the app requests.
So, if the app does not have INTERNET permission in its AndroidManifest.xml, it won't be granted access to INTERNET in that case?
Or will an app require to add INTERNET permission in its manifest in order to be able to make network calls?
As for the specific android.permission.INTERNET permission, it is still mandatory for apps that will access the Internet. If a developer were to publish an app without defining it in the Android manifest, an exception will be thrown the first time a connection attempt is made, and the app will possibly crash. This is no different than before.
All that has changed is that there won't be a prompt to the user, the app will still require the permission in the manifest.
Please check this video from Google IO - https://youtu.be/f17qe9vZ8RM?t=18m10s
There is no more Internet permission - the app will have by default access to the internet. Their idea is that if you don't have access to the device data then you can not do anything dangerous
Kind Regards

Categories

Resources