android - <使用权限> vs android :permission

标签 android android-permissions

有什么区别:

<uses-permission android:name="some_permission" />

<activity android:permission="some_permission" />

我的应用程序使用前者而不是后者并且仍然有效。我为什么要使用后者? 具体来说,为什么没有后者也能正常工作?

提前致谢...

最佳答案

虽然从结构和标签本身很清楚,即 uses-permission表示此权限将由应用程序和 android:permission 使用inside Activity 标签表示启动该 Activity 所需的权限。 以下是 uses-permission 之间的区别和 android:permission来自官方文档。

android:permission ( Activity 权限执行)

Permissions applied using the android:permission attribute to the tag in the manifest restrict who can start that Activity. The permission is checked during Context.startActivity() and Activity.startActivityForResult(). If the caller doesn't have the required permission then SecurityException is thrown from the call.

链接:https://developer.android.com/guide/topics/permissions/overview.html#permission_enforcement

uses-permission

Specifies a system permission that the user must grant in order for the app to operate correctly. Permissions are granted by the user when the application is installed (on devices running Android 5.1 and lower) or while the app is running (on devices running Android 6.0 and higher).

链接:https://developer.android.com/guide/topics/manifest/uses-permission-element.html

现在回答您的问题:

My application uses the former but not the latter and still works. Why would I use the latter? Specifically, why does it work without the latter?

回答:从上面的解释可以明显看出,如果您希望其他应用程序访问您的该 Activity ,则后者是必需的,即您的应用程序或 Activity 不需要该许可,但其他应用程序可以启动那个 Activity 。因此,如果没有后一个应用程序即 android:permission,您的应用程序将完美运行。

希望它有意义。

关于android - <使用权限> vs android :permission,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49743485/

相关文章:

android - 如何在google play控制台正确填写权限声明表?

java - 无法使用文件提供程序共享图像 java.lang.SecurityException : Permission Denial: reading androidx. core.content.FileProvider uri

android - GrantPermissionRule 授予权限失败

android - 检查 Android Market 上是否存在软件包

java - 删除后按后退按钮更新购物车计数

android - 在 Android 中使用 Alarm Manager 时,我应该声明权限 "com.android.alarm.permission.SET_ALARM"吗?

flutter - 如何在 Flutter 中请求和检查权限

java - 无法从 Activity 或类调用自定义 View (canvasview) 的方法

java - AsyncTask 一直在等待?

android - 在没有android :exported=false的情况下使NFC Activity 私有(private)