Android - Bind to a service from an other app

依然范特西╮ 提交于 2019-12-06 16:54:40

You should have a shared library between your service and application that defines the interface you use to communicate with the bound service.

UPDATE:
This solution and code example was valid at the time it was written at: 2015
Please look for other solution relevant for this day.

ORIGINAL ANSWER:
You can define an intent-filer for your service with a specific action and bind to this service with intent assigned to this action.

MyServiceApplication:

<service android:name=".MyService">
      <intent-filter>
        <action android:name="com.some.action.NAME" />
      </intent-filter>
</service>

MyActivityApplication:

bindService(new Intent("com.some.action.NAME"), serviceConnection, Context.BIND_AUTO_CREATE);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!