Is there any way to ask permission programmaticall

2019-01-12 05:25发布

Is there any way to ask permission programmatically in android ? I don't want to add all permission to AndroidManifest.xml. So is there any dialog that asks for permission at runtime?

6条回答
欢心
2楼-- · 2019-01-12 05:55

No. The user needs to be informed about the permissions while installing the application. Asking the user at runtime would be a security risk.

查看更多
仙女界的扛把子
3楼-- · 2019-01-12 05:56

Applications statically declare the permissions they require, and the Android system prompts the user for consent at the time the application is installed. Android has no mechanism for granting permissions dynamically (at run-time) because it complicates the user experience to the detriment of security.

查看更多
▲ chillily
4楼-- · 2019-01-12 05:57
The star\"
5楼-- · 2019-01-12 05:58

If I combine the answers from 'Piskvor' and from 'Hanno Binder', your app can check if the helper app is available (try to invoke it with an Intent), and if it is not there (the invocation fails), prompt the user to install it.

Look at the following, for example.

how to download adobe reader programatically if not exists

查看更多
Juvenile、少年°
6楼-- · 2019-01-12 06:04

Android M introduced Runtime permissions, which everyone has been waiting for. Also the permissions are now categorized into NORMAL and DANGEROUS, where NORMAL permissions are granted by default and DANGEROUS permissions are requested when they are needed. Also DANGEROUS permissions can be revoked by the user at any time from the device's Settings menu.

查看更多
迷人小祖宗
7楼-- · 2019-01-12 06:06

Not until now, but yes.

According to Google's new permission model introduced in Android M:

If an app running on the M Preview supports the new permissions model, the user does not have to grant any permissions when they install or upgrade the app. Instead, the app requests permissions as it needs them, and the system shows a dialog to the user asking for the permission.

Here's a summary of the key components of this new model:

  • Declaring Permissions: The app declares all the permissions it needs in the manifest, as in earlier Android platforms.

  • Permission Groups: Permissions are divided into permission groups, based on their functionality. For example, the CONTACTS permission group contains permissions to read and write the user's contacts and profile information.

  • Limited Permissions Granted at Install Time: When the user installs or updates the app, the system grants the app all permissions listed in the manifest that fall under PROTECTION_NORMAL. For example, alarm clock and internet permissions fall under PROTECTION_NORMAL, so they are automatically granted at install time. For more information about how normal permissions are handled, see Normal Permissions. The system may also grant the app signature permissions, as described in System components and signature permissions. The user is not prompted to grant any permissions at install time.
  • 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 user granted the permission. This permission model changes the way your app behaves for features that require permissions. Here's a summary of the development practices you should follow to adjust to this model:

  • Always Check for Permissions: When the app needs to perform any action that requires a permission, it should first check whether it has that permission already. If it does not, it requests to be granted that permission. You do not need to check for permissions that fall under PROTECTION_NORMAL.

  • Handle Lack of Permissions Gracefully: If the app is not granted an appropriate permission, it should handle the failure cleanly. For example, if the permission is just needed for an added feature, the app can disable that feature. If the permission is essential for the app to function, the app might disable all its functionality and inform the user that they need to grant that permission.

  • Permissions are Revocable: Users can revoke an app's permissions at any time. If a user turns off an app's permissions, the app is not notified. Once again, your app should verify that it has needed permissions before performing any restricted actions.

Source: https://developer.android.com/preview/features/runtime-permissions.html

查看更多
登录 后发表回答