<uses-permission> 对比 android:permission
<uses-permission> vs android:permission
有什么区别:
<uses-permission android:name="some_permission" />
和
<activity android:permission="some_permission" />
我的应用程序使用前者而不是后者并且仍然有效。我为什么要使用后者? 具体来说,为什么没有后者也能正常工作?
提前致谢...
<uses-permission>
是当您的应用程序正在寻求用户使用某些功能的许可时
例如:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<permission>
是指您的应用程序需要其他应用程序征求用户的许可才能使用您的某些功能。
例如:
<permission android:description="string resource"
android:icon="drawable resource"
android:label="string resource"
android:name="string"
android:permissionGroup="string"
android:protectionLevel=["normal" | "dangerous" |
"signature" | ...] />
您可以阅读:
https://developer.android.com/guide/topics/manifest/permission-element.html
虽然从结构和标签本身很清楚,即uses-permission
意味着这个权限将被应用程序使用,android:permission
里面 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.
Link: 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).
Link : 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
,您的应用程序将完美运行
希望它有意义。
总之,
<uses-permission android:name="some_permission" />
是您的应用程序应该保留的内容,以执行某些对用户数据敏感或危险的操作。
<activity android:permission="some_permission" />
是其他应用程序或您应用程序中的其他组件应该包含的内容,以便启动您的 activity。
有什么区别:
<uses-permission android:name="some_permission" />
和
<activity android:permission="some_permission" />
我的应用程序使用前者而不是后者并且仍然有效。我为什么要使用后者? 具体来说,为什么没有后者也能正常工作?
提前致谢...
<uses-permission>
是当您的应用程序正在寻求用户使用某些功能的许可时例如:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
<permission>
是指您的应用程序需要其他应用程序征求用户的许可才能使用您的某些功能。例如:
<permission android:description="string resource" android:icon="drawable resource" android:label="string resource" android:name="string" android:permissionGroup="string" android:protectionLevel=["normal" | "dangerous" | "signature" | ...] />
您可以阅读: https://developer.android.com/guide/topics/manifest/permission-element.html
虽然从结构和标签本身很清楚,即uses-permission
意味着这个权限将被应用程序使用,android:permission
里面 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.
Link: 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).
Link : 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
希望它有意义。
总之,
<uses-permission android:name="some_permission" />
是您的应用程序应该保留的内容,以执行某些对用户数据敏感或危险的操作。
<activity android:permission="some_permission" />
是其他应用程序或您应用程序中的其他组件应该包含的内容,以便启动您的 activity。