Permission issue while starting a service from android

三世轮回 提交于 2019-11-30 17:50:16

The service isn't available to other applications because you haven't made it explicitly available. Your service needs to be defined like this:

<service android:name="DownloadService"
         android:exported="true">
</service>

You don't need any extra permissions (unless you want to use them)

Have your read the documentation? It is quite clear with this issue:

Global access to a service can be enforced when it is declared in its manifest's tag. By doing so, other applications will need to declare a corresponding element in their own manifest to be able to start, stop, or bind to the service.

As of GINGERBREAD, when using Context.startService(Intent), you can also set Intent.FLAG_GRANT_READ_URI_PERMISSION and/or Intent.FLAG_GRANT_WRITE_URI_PERMISSION on the Intent. This will grant the Service temporary access to the specific URIs in the Intent. Access will remain until the Service has called stopSelf(int) for that start command or a later one, or until the Service has been completely stopped. This works for granting access to the other apps that have not requested the permission protecting the Service, or even when the Service is not exported at all.

In addition, a service can protect individual IPC calls into it with permissions, by calling the checkCallingPermission(String) method before executing the implementation of that call.

See the Security and Permissions document for more information on permissions and security in general.

Show us your AndroidManifest.xml if you still have permission problems after reading the documentation. Also see the exported and the permission attribute of the service in your manifest.

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