Issue
First app has a service:
<service
android:name="com.example.app.service.MyService"
android:exported="true">
<intent-filter>
<action android:name="com.example.app.START_MY_SERVICE" />
</intent-filter>
</service>
Another app starts a service of the first app using (3 possible methods):
1:
val i = Intent("com.example.app.START_MY_SERVICE").apply {
setPackage("com.example.app")
}
startService(i)
2:
val i = Intent().apply {
component = ComponentName("com.example.app", "com.example.app.service.MyService")
}
startService(i)
3:
val i = Intent().apply {
setClassName("com.example.app", "com.example.app.service.MyService")
}
startService(i)
All these methods to start a service of another app work from 23 API (6 Android) to 29 API (10 Android)
On Android 11 (30 API) it doesn't work, a service doesn't start, no exception:
When using 2-3 methods, in Logcat it prints:
W/ActivityManager: Unable to start service Intent { cmp=com.example.app.service/.service.MyService } U=0: not found
For 1 method nothing happens at all, no message at Logcat
So how can we start a service of some app from another app on Android 11?
Solution
The app that starts a service of another app must include the next declaration in manifest:
<queries>
<package android:name="com.example.anotherapp" />
</queries>
or
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
(apps like Automate and Tasker have this permission)
Thanks to CommonsWare Android 11: starting a service of another app
Answered By - user924
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.