Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
190 views
Welcome To Ask or Share your Answers For Others

1 Answer

An Android Service can have multiple permissions, but permissions are granted at the application level, not at the Service level.

Your problem is that you are trying to grant permission to your Service in the wrong place in the AndroidManifest.xml file.

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.

You grant permissions to all components your application at the top level of your 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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...