有什么区别:
<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/