问题
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