android:permission in <application>

£可爱£侵袭症+ 提交于 2019-12-08 10:23:18

问题


I have noticed that Android framework allows android:permission in <application>. For example, consider the following manifest file.

<application android:permission="android.permission.INTERNET">
    ...
</application>

In the above example, to launch my application the launcher app (e.g., home screen) needs INTERNET permission. In reality, no one permission protect their application (I may be wrong here). But, I really don't understand the practical use-case of it. When will we use permissions in <application>?


回答1:


Quoting the documentation:

This attribute is a convenient way to set a permission that applies to all of the application's components

So, if every <activity>, <service>, <provider>, and <receiver> in your manifest would have the same android:permission attribute, you could eliminate the redundancy and simply have the attribute in <application>.

In practice, I suspect that this is almost never used, except perhaps by plugin apps restricted to work only with some host app via a signature-level permission.




回答2:


Try to put like the following outside application tag:

 <uses-permission android:name="android.permission.INTERNET" />

And also if we need to perform any special permissions, you need to specify the respective permissions in manifest.



来源:https://stackoverflow.com/questions/18418240/androidpermission-in-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!