There are two apps, first one has a service and can start it. Second one tries to start the service from the first app and cannot because the service is "not found". I believe that the service is enabled and exported (see code below). What's wrong?
The manifest of the first app with declaration of the service:
<manifest ...
package="com.example.fooapplication">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application ...>
<service
android:name=".FooService"
android:enabled="true"
android:exported="true">
</service>
<activity android:name=".MainActivity" ...>
...
</activity>
</application>
</manifest>
From that application I can start the FooService by the following commands:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example.fooapplication", "com.example.fooapplication.FooService"));
Log.d("happy", "FooApplication " + intent);
startService(intent);
It works, there is the log (two last lines are from the service itself):
12-19 10:18:58.520 12869 12869 D happy : FooApplication Intent { cmp=com.example.fooapplication/.FooService }
12-19 10:18:58.568 12869 12869 D happy : FooService constructor
12-19 10:18:58.568 12869 12869 D happy : FooService onCreate
The same code sequence at the second app cannot start that service:
12-19 10:31:22.300 13644 13644 D happy : BarApplication Intent { cmp=com.example.fooapplication/.FooService }
12-19 10:31:22.301 1712 3872 W ActivityManager: Unable to start service Intent { cmp=com.example.fooapplication/.FooService } U=0: not found
Building parameters for both applications are:
compileSdkVersion 30
buildToolsVersion "30.0.0"
minSdkVersion 23
targetSdkVersion 30
Device with Android 12 (SDK 31)