0

It's probably a very simple question but since I'm new to android development...

I am trying to start a service from an activity that is not in the same package (remote service) with the following code:

Intent i = new Intent("com.vasilis.service.GPSService");
i.putExtra("com.vasilis.service.GPSEnable", true);
this.startService(i);

but nothing happens with this code!

the manifest of the service project/package...

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.vasilis.service" android:versionCode="1" android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".serv_activity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

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

        <activity android:name=".incomingCallActivity" android:label="@string/app_name"
            android:theme="@android:style/Theme.Dialog"></activity>

        <receiver android:name="OnBootCompleteReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"></action>
            </intent-filter>
        </receiver>

    </application>
    <uses-sdk android:minSdkVersion="7" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
</manifest> 

I am missing something! Any help ?

Vassilis
  • 2,878
  • 1
  • 28
  • 43

1 Answers1

1

A similar question was asked here: How do I start a service which is defined in a different package?

Pretty much you just need to add this to the manifest.xml

<service android:name=".GPSService" android:exported="true" android:enabled="true">
    <intent-filter>
        <action android:name="com.vasilis.service.GPSEnable" />
    </intent-filter>
</service>

Or whatever the names of the classes are ;) If this doesn't seem to work, the documentation located at Service has a lot of good advice.

Community
  • 1
  • 1
Bob
  • 1,219
  • 1
  • 14
  • 28