调用其它app中的Service

来源:互联网 发布:淘宝卖家不同意退货 编辑:程序博客网 时间:2024/06/06 02:36

涉及到IPC,用Messenger实现IPC,参见:http://developer.android.com/guide/components/bound-services.html


在Service的工程的Manifest文件中做如下声明:

<service android:name="com.boyaa.service.MyMessengerService"
            android:exported="true">
            <intent-filter>
                <action android:name="com.boyaa.service.action.BIND_SERVICE"/>
            </intent-filter>
</service>


在Client工程中,通过如下方式调用:

Intent intent = new Intent();
intent.setClassName("com.boyaa.service", "com.boyaa.service.MyMessengerService");
MainActivity.this.bindService(intent, MainActivity.this, Context.BIND_AUTO_CREATE);


或者


Intent intent = new Intent();
intent.setAction("com.boyaa.service.action.BIND_SERVICE");
MainActivity.this.bindService(intent, MainActivity.this, Context.BIND_AUTO_CREATE);

原创粉丝点击