android 直接启动其他应用的Service

最近在做一个小插件,没有图标没有activity,利用其他APK启动它的service。

直奔主题,插件A,安装插件的应用B.

B安装A后,由于A刚被安装,没有注册广播接收器,这里不考虑AIDL。需求需要在B安装完A后让A的service启动。

代码和启动activity类似。

Intent intent = new Intent();
                intent.setComponent(new ComponentName("com.a.b.c",
                        "com.a.b.c.XXService"));
                intent.setAction(Intent.ACTION_VIEW);
                startService(intent);

但是需要给com.a.b.c.XXService配置一个属性:

<service
            android:name="com.a.b.c.XXService"
            android:exported="true" />

即可。

posted @ 2014-08-05 15:49  带狗狗带  Views(1812)  Comments(0Edit  收藏  举报