12

I am trying to start the service from adb shell. There already is similar question: How to start and stop android service from a adb shell? However, when I start service with:

adb shell am startservice com.mypackage/com.mypackage.service.MyService

I receive this message:

Starting service: Intent { act=android.intent.action.VIEW dat=com.mypackage/com.mypackage.service.MyService }
Error: Not found; no service started.

I declare service in AndroidManifest.xml:

<application>
  ...
  <service
    android:name="com.mypackage.service.MyService"
    android:label="@string/local_service_label"
    android:icon="@drawable/ic_launcher">
  </service>
</application>

Do you have any idea how to solve this? Thank you!

Community
  • 1
  • 1
stevo.mit
  • 4,681
  • 4
  • 37
  • 47

4 Answers4

16
adb shell am startservice -n com.mypackage/.service.MyService

Update (Per adb shell am help start-service):

-n <COMPONENT_NAME>

copolii
  • 14,208
  • 10
  • 51
  • 80
Jaybo
  • 944
  • 10
  • 13
  • 1
    A single command may answer the question, but it would be useful to explain what `-n` does. You might also want to indent any code by 4 spaces. – ronalchn Sep 20 '12 at 09:17
  • 1
    "am startservice" help lists [-n ] (it does not relate to line numbers) – dricket Aug 11 '15 at 01:44
4

Consider the below as an example

<application android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:theme="@style/AppTheme">
    <service
        android:name=".MyService"
        android:description="@string/Desciption"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="com.nandhan.myservice" />
        </intent-filter>
    </service>        
</application>

Then I would start the service as below

adb shell am startservice com.nandhan.myservice/.MyService

Nandhan Thiravia
  • 360
  • 2
  • 12
4

In my case, the service failing to start was com.android.tools.fd.runtime.InstantRunService.

Starting service: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.xxx.xxx/com.android.tools.fd.runtime.InstantRunService } Error: Not found; no service started.

Turns out my android device was missing something. To disable it, go to preferences > Build, Execution, Deployment > Instant Run and uncheck Enable Instant Run to hot swap code/resource changes on deploy (default enabled).

disable instant run

According to that screenshot, it's better to keep it and indeed, I'd be happier with that feature. At least I ran with extra logging and sent feedback to google. I just needed a build asap so no instant run for me today ;)

GabLeRoux
  • 16,715
  • 16
  • 63
  • 81
1

Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
    package="com.xyz.path">

...

<application

...

    <service android:name=".MyService">
        <intent-filter>
            <action android:name="com.xyz.path.MY_SERVICE" />
        </intent-filter>
    </service>

...

Command:

adb shell am startservice -n com.xyz.path/.MyService
powder366
  • 4,351
  • 7
  • 47
  • 79