How to start a service that is defined in another package?

I have two applications: one works in the com.gtosoft.voyager namespace, and the other com.gtosoft.dash. From com.gtosoft.dash, I would like to start the service that is defined in com.gtosoft.voyager ...

I think I need an intention, but what arguments would I pass on to the intention before starting with startService ()?

If they were in the same package, I could just use

Intent svc=new Intent (SettingsActivity.this,VoyagerService.class);
startService(svc);

A fragment of the manifest that defines the service

<application android:icon="@drawable/voyagercarlogo" android:label="@string/app_name" android:debuggable="false">

    <provider android:name="com.gtosoft.voyager.VoyagerCProvider" 
        android:authorities="com.gtosoft.voyager"/>

    <service android:name=".VoyagerService"/>

    <activity android:name=".SettingsActivity" 
            android:label="Voyager"
            android:configChanges="keyboardHidden|orientation">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
+3
source share
2 answers

<intent-filter> , , Intent . client service.

+4

CommonsWare 2010 , , setComponent . ,

com.xyz.app1:

Intent i = new Intent();
String pkg = "com.xyz.app2";
String cls = "com.xyz.app2.MyService";
i.setComponent(new ComponentName(pkg, cls));
startService(i);
+9

Source: https://habr.com/ru/post/1742681/


All Articles