Java 一个 Android 服务可以有多个权限吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3473911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can an Android Service have multiple Permissions?
提问by Aymon Fournier
I have a service which both downloads a file and saves it, and it seems I can only specify one permission.
我有一项既下载文件又保存文件的服务,看来我只能指定一个权限。
<service android:enabled="true"
android:name=".DownloadService" android:permission="android.permission.INTERNET">
</service>
or
或者
<service android:enabled="true"
android:name=".DownloadService" android:permission="android.permission.WRITE_EXTERNAL_STORAGE">
</service>
I need both.
我两个都需要。
采纳答案by Dave Webb
An Android Service
can have multiple permissions, but permissions are granted at the application level, not at the Service
level.
一个 AndroidService
可以有多个权限,但权限是在应用程序级别授予的,而不是在Service
级别。
Your problem is that you are trying to grant permission to your Service
in the wrong place in the AndroidManifest.xml
file.
您的问题是您试图Service
在AndroidManifest.xml
文件中的错误位置授予您的权限。
The android:permission
attribute of a Service
specifies the permission that an entity must have to use the service, not a permission granted to the Service
.
a 的android:permission
属性Service
指定实体必须拥有使用服务的权限,而不是授予 Service
.
You grant permissions to all components your applicationat the top level of your AndroidManifest.xml
:
您在您的顶级应用程序中授予对所有组件的权限AndroidManifest.xml
:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourdomain.yourapp" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>