How to call a Service through another app?

Asked

Viewed 357 times

0

I have two apps, the app 1 has several CRUD, the app 2 has several services and notifications.

When trying to start Service by App 1, this is happening:

java.lang.Securityexception: Not allowed to start service Intent { Cmp=com.example.Luiz.servicelocation/. Locationservice } without permission not Exported from uid 10059

Could I start a service of my app 2 through a button in my app 1?

  • This link explains how to communicate between apps https://web.archive.org/web/20130731024012/http://code.google.com/p/openmobster/wiki/Interappcommunication

  • This is happening: Caused by: java.lang.Securityexception: Not allowed to start service Intent { Cmp=com.example.Luiz.servicelocation/. Locationservice } without permission not Exported from uid 10059

  • 2

    I think it worked, this setup <service android:name=". Locationservice" android:enabled="true" android:Exported="true" />

  • @Luizlanza Publish your solution as an answer to make life easier for those who have the same problem in the future.

  • Solution equal to @jdoper

1 answer

1


First look at your Androidmanifest.xml and copy the content into a package, in the case of "com.example.pedro.".

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pedro.aplicativo" ></manifest>

In your Activity use the code below, in the package variable put what you copied from package (with.example.pedro.app) and in the variable put the name of the service class you want to call (with.example.pedro.aplicativo.Meuservico).

import android.content.ComponentName;

Intent intent = new Intent();
String pacote = "com.example.pedro.aplicativo";
String classe = "com.example.pedro.aplicativo.MeuServico";
intent.setComponent(new ComponentName(pacote, classe));
startService(intent);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.