简体   繁体   中英

Android adb shell am startservice: Error not found

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!

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

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

-n <COMPONENT_NAME>

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

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) .

禁用即时运行

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 ;)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM