Android start service of an app from another android app

谁都会走 提交于 2019-12-24 14:17:05

问题


I have two applications installed on the device: from one app I want to start a service as follows:

Intent i = new Intent();
   i.setComponent(new ComponentName("com.app.service",    "com.app.service.NotificationService"));
  context.startService(i);

The second app is only installed but not started.

What I want is to start the notification service(which should create a notification) from the second service by using the above code.

In the manifest file of the second app I declare the service as follows:

<service
        android:name=".service.NotificationService"
        android:exported="true" />

The problem is that the Notification Service from the second app does not start.

Any ideas on why this happens?


回答1:


Just to be clear, the second app is the Notifications one right?

If so, what I would try is loading both apps individually first, and then creating a method in your second one to access the information from the first one.

I had a similar scenario, let me just find the solution (somewhere on my laptop) and get back to you more specifically.




回答2:


Not exactly a great solution but I have fixed my problem by removing the NotificationService file from the com.app.service directory, and adding it to the com.app directory. This fixed the issue for me, meaning that I managed to start the service of the second application from the first application.



来源:https://stackoverflow.com/questions/31605866/android-start-service-of-an-app-from-another-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!