我如何启动(和绑定)在另一个应用程序(不同的包)中实现的android中的远程服务?

xen*_*ite 8 service android

我在android中遇到了远程服务.事情是我在包"abc"中实现了远程服务,我希望其他应用程序能够访问此服务.我摆脱了整个蹩脚的援助,并设计了服务的"界面",通过广播意图工作.到目前为止工作正常......

problem is: how do i get a different application (different package, different project, maybe even a different developer, ...) to start/stop the service?

package d.e.f;

import a.b.c.*;

public class main extends Activity {
    protected ImyService myService;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Intent intent = new Intent(ImyService.class.getName());
        bindService(intent, sConnection, Context.BIND_AUTO_CREATE);
    }

    protected ServiceConnection sConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder binder) {
            wlService = ImyService.Stub.asInterface(binder);
            ServiceConnected = true;
            Toast.makeText(main.this, "service connected", Toast.LENGTH_SHORT).show();
        }

        public void onServiceDisconnected(ComponentName className) {
            wlService = null;
            ServiceConnected = false;
            Toast.makeText(main.this, "service disconnected", Toast.LENGTH_SHORT).show();
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

this will crash my app immediately on startup. what did i do wrong? how will i get this to work?

once it's running, commands and data will be passed via broadcasts. so that should be no real problem...

Com*_*are 20

步骤#1:使用字符串<intent-filter>为您设置<service>一个<action>.

第2步:使用操作字符串为Intent您使用bindService()(例如new Intent("this.is.my.custom.ACTION"))

  • @JPM:请参阅https://github.com/commonsguy/cw-advandroid/blob/master/AdvServices/RemoteService/AndroidManifest.xml (3认同)