问题
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