Android adb shell am startservice:找不到错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12347440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:27:32  来源:igfitidea点击:

Android adb shell am startservice: Error not found

androidadb

提问by stevo.mit

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 启动服务。已经有类似的问题:How to start and stop android service from a adb shell? 但是,当我开始服务时:

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:

我在 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!

你知道如何解决这个问题吗?谢谢!

回答by Jaybo

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

-nadds 'line_no:' prefix

-n添加“line_no:”前缀

回答by GabLeRoux

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

就我而言,无法启动的服务是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.

启动服务: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.xxx.xxx/com.android.tools.fd.runtime.InstantRunService } 错误:未找到;没有服务启动。

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

原来我的安卓设备丢失了一些东西。要禁用它,请转到preferences > Build, Execution, Deployment > Instant Run并取消选中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 ;)

根据那个截图,最好保留它,事实上,我会对这个功能更满意。至少我运行了额外的日志记录并向谷歌发送了反馈。我只需要尽快构建,所以今天我没有立即运行;)

回答by Nandhan Thiravia

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

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

回答by powder366

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