Android: unable to start service intent: not found?

39,887

Solution 1

So.. just to eventually help others or not:

I made a new project, copied the sources and tried to run it: the service was found now. What was the difference, or in other words: what do I think, might give problems: the long package name or the beginning with com.android... In the new project I just chose com.enocean

Solution 2

Thanks to user njzk2 for letting me notice what was happening.

I've had the same problem. It seem that Android OS can't find the service class that you've requested if you haven't registered before in the manifest file of your proyect.

Remember that a service is like an activity but without graphic interface. It means that the services needs to be registered before you can use them

This is how you register the service in your Android project:

<application>
    <!-- your code -->
    <activity>
        <!-- your code  -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <service android:name="com.your.own.service.class"></service>
</application>

Just Remember that YourService class needs to extend from Service, if not your class won't be a service.

public class YourService extends Service{}

Solution 3

Sometimes you'll need to fully qualify your class name in the manifest, rather than using the shortform (.classname). I've seen that when I used classes from a different package, but perhaps it would help here since the service intent may go outside of the app.

Solution 4

Despite ALL the answers in this post and many related Unable to start service Intent: not found Unable to start Service Intent , I still struggled and it took some time for me to get this going. My scenario was slightly more complicated since I'm trying to start a service in a DIFFERENT app that the one I'm calling it with. I figured it out and here are ALL the details, along with some bonus code.

MainActivity of calling intent (or whereever)

Intent intent=new Intent("com.example.core.MusicService.1234");
//Or Intent intent=new Intent("com.example.core.MusicService.TOGGLE_PLAYBACK");
PendingIntent pendingIntent = PendingIntent.getService(this, 99, intent, PendingIntent.FLAG_CANCEL_CURRENT);

Manifest: of Service (Service tag inside Application tag) It's

    <service android:name="com.example.core.MusicService">
        <intent-filter>
            <action android:name="com.example.core.MusicService1234"></action>
        </intent-filter>
        <intent-filter>
            <action android:name="com.example.core.MusicService.TOGGLE_PLAYBACK"></action>
        </intent-filter>
    </service>

MusicService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if(intent != null){
        if(intent.getAction() != null){
            if(intent.getAction().contentEquals("com.example.core.MusicService.TOGGLE_PLAYBACK")){
                //Do work here
            }
        }
    }
}

Notes

  • Service does NOT need to be started, this intent will start it
  • "com.example.core.MusicService1234" and "com.example.core.MusicService.TOGGLE_PLAYBACK" can be whatever you want it to be, but obviously needs to match the intent-filter in the service manifest with the calling intent. You can put multiple of these so you can do different actions when your service starts depending on the value from your intent
  • 99 can be whatever you want, but must be unique if you're using notifications
  • I'm not sure it's possible to call a service in a different app (like this) without using the intent-filter - if it is, someone please enlighten us. I tried and it doesn't work.

Credit to: the cumulative information from all the posts :)

Share:
39,887
nico
Author by

nico

Updated on April 30, 2020

Comments

  • nico
    nico about 4 years

    I know, I am not the first onbe with this problem, but I tried so many solutions, I have found and no one works... maybe you could find the error

    The error (also came so without .class and with /.Client depending on other settings)

    12-02 16:40:15.359: W/ActivityManager(74): Unable to start service Intent { act=com.android.fh.EnOceanApp.Client.class }: not found

    In the manifest, this is included in application, out of activities (tried it also in activities and with ".Client"

    The code in onCreate()

        startService(new Intent(this, Client.class)); 
    

    or

     startService(new Intent(this.getApplicationContext(), Client.class));
    

    or

    Intent intent=new Intent("com.android.fh.EnOceanApp.Client.class");
        this.startService(intent);
    

    or

      Intent intent=new Intent("com.android.fh.EnOceanApp.Client");
        this.startService(intent);
    

    And now, I dont have an Idea anymore.... com.android.fh.EnOceanApp is the package, Client.java the service-class in this package

    and the manifest I forgot:

      <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <activity
                android:label="@string/app_name"
                android:name=".EnOceanAppActivity" >
                <intent-filter >
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>      
            </activity>
    
          <activity android:name=".ListView" 
              android:label="List View">
          </activity> 
          <activity android:name=".GraphView" 
              android:label="Graph View">
          </activity>
          <service 
                android:name=".Client"></service> //with and without ., of course without this comment
        </application>
    
  • nico
    nico over 12 years
    This doesn´t change anything so far :(
  • Tirtha
    Tirtha over 11 years
    Helped me. I had my service in a different package than my main activity
  • Petr Prazak
    Petr Prazak over 10 years
    com.andorid.* is restricted on the Playstore (Just FYI)
  • Danail
    Danail over 10 years
    Had the same problem, and noticed that if I close the tag with "/>" it doesn't detect the service after app upgrade, but if I close with "</service>" then it detects it after app upgrade. Weeiird.
  • Danail
    Danail over 10 years
    @Konstantin, think you just need to clear the entire project. That was the issue for me.
  • OneWorld
    OneWorld over 9 years
    @Danail I just had to make a minor change in the Manifest, like adding a label to any service. That seemed to update the Manifest stored in my device. I could remove my change afterwards. Project > Clean could also do the trick. It happened after updating the app via Eclipse. While updating I was asked to delete the existing app due to signature mismatch. I did so. Afterwards the old Manifest probably stayed on the device but my new app required a newer Manifest.
  • Lisitso
    Lisitso about 9 years
    this answer looks interesting but there's no so much code to try the solution provided
  • strangetimes
    strangetimes over 7 years
    @scottyab turns out my app's package name is com.mycompany.androidapp ... so it seems it's performing some regex and the com...*android* matched and is probably causing problems? I can't change my package name now.. now what?