Android adb shell am startservice: Error not found - android

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

Related

Android Studio, how to deal with adb error?

I think my issue has something to do with the adb. I searched a lot online and tried to shut it down about 4 different ways and nothing helps. I am using a Mac. Here is what the Run tab of Android Studio says when I run my app:
06/16 16:36:06: Launching app
$ adb push /Users/melloo/Desktop/UCI/Intro-to-Mobile-App-Development-with-
Android/A2-Antoniya.Puleva/app/build/outputs/apk/app-debug.apk
/data/local/tmp/x40240.antoniya.puleva.a2
$ adb shell pm install -r "/data/local/tmp/x40240.antoniya.puleva.a2"
pkg: /data/local/tmp/x40240.antoniya.puleva.a2
Success
$ adb shell am start -n
"x40240.antoniya.puleva.a2/x40240.antoniya.puleva.a2.MainActivity" -a
android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Connected to process 2983 on device Nexus_5X_API_22 [emulator-5554]
Application terminated.
and my manifest:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:launchMode="standard"
>
<activity android:name=".MainActivity"
android:label="List O'Names">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NameListActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name = "x40240.antoniya.puleva.intent.action.ACTION_VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
</application>
Had similar error using Android Studio 3.0 Canary 3. Try doing following things:
Update your Android Studio to the latest version (if you are using 3.0, Canary 4 just came out yesterday)
I see you are using Emulator with Lolipop (api 22), try creating new device with api 25 (Nougat)
Try doing some change in manifest (like adding empty line, the point is to just change the manifest file), then go Build->Clean project and to run it again.

Android UI tester monkey - no activities found to run

I am trying to get the android ui monkey running for the first time and am having some problems.
I have run adb shell monkey -v 100 which works fine, but obviously only on the system UI not on my own application.
I then try
adb shell monkey -p com.rbennett485.dawnoftheveg -v 100
and get the output
:Monkey: seed=1406692871132 count=100
:AllowPackage: com.rbennett485.dawnoftheveg
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
** No activities found to run, monkey aborted.
The relevant section of my manifest is
<activity
android:name="com.rbennett485.dawnoftheveg.DawnOfTheVeg"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MONKEY" />
</intent-filter>
</activity>
Any ideas? I know a lot has been asked about this error before, but it mostly seems to be from not using the full package name - am I using the correct package name here?
Turned out the package my main activity was in had a different name to the package that was defined in my manifest. By using the manifest package name instead it worked fine

Cannot launch activity from adb

I have the following in my AndroidManifest.xml (I just added a second activity to the default project):
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.com.testapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.com.testapp.TestActivity"
android:label="#string/title_activity_test" >
<intent-filter>
<action android:name="com.testapp.action.TEST_ACTION" />
</intent-filter>
</activity>
I want to launch the TestActivity using adb command. I tried:
./adb shell am start -a com.testapp.action.TEST_ACTION
But it gives the error:
Error: Activity not started, unable to resolve Intent { act=com.testapp.action.TEST_ACTION flg=0x10000000 }
Can someone please explain why I am getting this error and how to resolve it?
Edit :
Can anyone tell a way to just use action to launch the 'TestActivity'.
I think you should add the code below into your intentfilter
<category android:name="android.intent.category.DEFAULT"/>
try using:
adb shell "am start -n com.example.com.testapp/.TestActivity -a com.testapp.action.TEST_ACTION"
or
adb shell "am start com.example.com.testapp -a com.testapp.action.TEST_ACTION"
hope that works.
Try adb shell am start -n com.mypackage.name/com.mypackage.name.TEST_ACTION (replace the package names and activity names as needed)
Take a look at this solution.
To expand on what 陈薛星 wrote, in the "Android developer guide on Intent Filters" under "Category Test", it states
Note: Android automatically applies the CATEGORY_DEFAULT category to all implicit intents passed to startActivity() and startActivityForResult(). If you want your activity to receive implicit intents, it must include a category for "android.intent.category.DEFAULT" in its intent filters, as shown in the previous example.
So you need to add
<category android:name="android.intent.category.DEFAULT"/> to your intent filter.
This will match an implicit intent. (Several other answers show how to target a class explicity).

Is there a difference between starting an application from the OS or from adb

I do have a curious error in my application.
My app crashes (don't mind the crash, I roughly know why - classloader) when I start the application from the OS directly, then kill it from the background via any Task Killer (this is one of the few ways to reproduce the crash consistently -> simulating the OS freeing memory and closing the application) and try to restart it again.
The thing is, if I start the application via adb shell using the following command:
adb shell am start -a android.intent.action.MAIN -n com.my.packagename/myLaunchActivity
I cannot reproduce the crash.
So is there any difference in how Android OS calls the application as opposed to the above call?
EDIT: added the manifest (just changed names)
<?xml version="1.0" ?>
<manifest android:versionCode="5" android:versionName="1.05" package="com.my.sample" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="7"/>
<application android:icon="#drawable/square_my_logo" android:label="#string/app_name">
<activity android:label="#string/app_name" android:name="com.my.InfoActivity" android:screenOrientation="landscape"></activity>
<activity android:label="#string/app_name" android:name="com.my2.KickStart" android:screenOrientation="landscape"/>
<activity android:label="#string/app_name" android:name="com.my2.Launcher" android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/></manifest>
starting the com.my2.Launcher from the adb shell
First thing I can see is that if you launch the app from the launcher icon, the Intent includes the CATEGORY "android.intent.category.LAUNCHER" and using the adb shell am it does not.
Also, when you launch via the launcher icon, the Intent flag FLAG_ACTIVITY_RESET_TASK_IF_NEEDED (0x200000) is set, in the adb shell case it is not.
Not sure if any of that would make a difference in your crash behaviour, but it answers the question.

How to launch my Android application using adb shell?

I'm trying to start an Android application using adb shell.
I'm not succeeding
The AndoridManifest.XML is pasted below:
<?xml version="1.0" encoding="UTF-8"?>
<manifest android:versionCode="4" android:versionName="0.0.5.0" android:installLocation="auto" package="com.supascale.supascale" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:label="#string/app_name" android:icon="#drawable/i_c_o_n_e________1">
<activity android:theme="#android:style/Theme.Translucent" android:label="#string/app_name" android:name=".wdgen.GWDPSupaScale_Android$WDLanceur">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
I tried the following call:
adb shell am start -a android.intent.action.MAIN -n com.supascale.supascale/com.supascale.supascale.wdgen.GWDPSupaScale_Android
This does'nt work ... I've tried all sorts of itterations after the ... /
I get Error type 3, the intent class does not exist!
Any help will be greatly appreciated.
Regards
Adrian
Some of my error messages:
You should escape the $ - \$ - since otherwise it gets changed to nothing. $WDLanceor is interpreted as a shell variable by the android shell, and since the variable is not set it becomes an empty string.
Quoting the arguments (adb ... -n "... GWDPSupaScale_Android$WDL‌​a‌​nceur") will only quote it on the Windows side, when it goes into the shell on the android side it'll be without quotes. The backslash will survive the Windows command prompt and be converted to an actual $ on the android shell.

Categories

Resources