How to start android service from another Android app

前端 未结 2 1115
梦如初夏
梦如初夏 2020-12-04 18:39

I\'m having a problem starting a service from another Android app (API 17). However, if I do run \'am\' from the shell, the service starts fine.

# am startse         


        
2条回答
  •  臣服心动
    2020-12-04 18:43

    You should be able to start your service like this:

    Intent i = new Intent();
    i.setComponent(new ComponentName("com.xxx.yyy", "com.xxx.yyy.SyncService"));
    ComponentName c = ctx.startService(i);
    

    You don't need to set ACTION or CATEGORY if you are specifying a specific component. Make sure that your service is properly defined in the manifest.

提交回复
热议问题