Android adb shell am startservice: Error not found

送分小仙女□ 提交于 2021-02-06 16:34:40

问题


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!


回答1:


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

-n adds 'line_no:' prefix




回答2:


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




回答3:


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




回答4:


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


来源:https://stackoverflow.com/questions/12347440/android-adb-shell-am-startservice-error-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!