android: how to control starting/finishing an app from command line - android

I know we can use
adb shell am start -n [package]/[activity] to start an launcher activity.
But does anyone know how to close it?
Thanks

Have an activity that calls finish() when it receives a particular action. Then send this action using the am command.

Related

Is it possible to pass an intent ... or intent extras ... to an Android app in the debugger?

I'm working on an activity that is designed to livestream a video to a given URL when started. It doesn't really have it's own user interface, to speak of. It is started by another android app, using an intent, and the url is passed to it in the intent.
So I'm running it in the debugger, and I have no idea how to pass the URL.
Of course I can just hardcode on while I'm debugging, but it seems hard to believe that with all the intents flying around under android, that it never occurred to anybody that you might want to debug what happens when your activity is started by some offbeat intent.
So have I missed something?
you can use ADB command to send a broadcast.
adb shell am start|startservice|broadcast <INTENT>[<COMPONENT>]
-a <ACTION> e.g. android.intent.action.VIEW
-c <CATEGORY> e.g. android.intent.category.LAUNCHER (start activity intent)
ref from link:
https://www.automatetheplanet.com/adb-cheat-sheet/

android osmand api with am commands

on my android phone I want to control osmand using the osmand api. To send the intents I want to use the am command available in adb shell or termux.
I am able to start osmand with am start net.osmand.plus/net.osmand.plus.activities.MapActivity
In my first test I just want to stop the navigation (command: STOP_NAVIGATION).
First I tried am start -a stop_navigation -n net.osmand.plus/net.osmand.plus.activities.MapActivity. The result was Starting: Intent { act=stop_navigation cmp=net.osmand.plus/.activities.MapActivity } Warning: Activity not started, its current task has been brought to the front, which makes sense.
Then I tested some broadcast commands, e.g.:
am broadcast -a stop_navigation -n net.osmand.plus/net.osmand.plus.activities.MapActivity
am broadcast osmand.api://stop_navigation
I also tested it with capital letters. But no command was successful.
Is there someone which has more experiences with android intents and / or osmand api and can help me how to create a working command?
Thanks in advance!
I already found the solution, it was simpler than expected. Maybe I can help someone with the solution:
The command am start osmand.api://pause_navigation is enough.
BTW:
termux-open osmand.api://pause_navigation does also work.

Is it possible to start an activity via ADB without animation

I know it's possible to have no animation when starting an activity via code (here, for example), but is it possible to do so via adb too, even for activities that were supposed to have an animation ?
Also, is it possible to have no animation when going back from this opened activity?
Looking at the ADB Shell Activity Manager specification for arguments here: https://developer.android.com/studio/command-line/shell.html#IntentSpec
we can see that there is a -f option for Intent flags.
Th Intent flag FLAG_ACTIVITY_NO_ANIMATION has constant value: 65536
See: https://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NO_ANIMATION
Putting that together you could write something like:
am start -a com.example.ACTION_NAME -n com.package.name/com.package.name.ActivityName -f 65536
you can use the below command to start an activity via adb,
am start -n yourpackagename/.activityname

How to launch an Android SubSettings Fragment?

For example, how do I launch User Settings? It's not implemented as its own Activity, so I'm not sure how to start it.
Below are some other similar questions but these are either more general or more specific. My question is about starting an arbitrary SubSettings fragment.
How do I call a specific PreferenceFragment from a PreferenceActivity?
Show only wireless system settings on Android 3
You can launch most Android Settings sub-screens by starting the SubSettings Activity and including the :android:show_fragment extra with the appropriate fully-qualified class name of an existing Android PreferenceFragment subclass.
For example, to start UserSettings:
adb shell am start -n com.android.settings/com.android.settings.SubSettings -e :android:show_fragment com.android.settings.users.UserSettings
To start DeviceInfoSettings:
adb shell am start -n com.android.settings/com.android.settings.SubSettings -e :android:show_fragment com.android.settings.DeviceInfoSettings
These examples use 'adb shell am start', but in principle you could invoke these in Java code (EDIT: Unfortunately you need to be signed with the system key, otherwise you get a SecurityException). Notice that the key for this extra has a colon at the front of it. To find other Settings, checkout the Android source and look for subclasses of PreferenceFragment in the packages/apps/Settings.
The situation was different in Froyo and before. In those days Activities were used to implement Settings sub-screens, so one could launch directly into a sub-screen (for example SoundAndDisplaySettings) by the usual method of calling startActivity() with a ComponentName or action String. This mechanism still works for some Settings sub-screens. For example, to bring up a wifi picker, you can use
adb shell am start -a android.net.wifi.PICK_WIFI_NETWORK
for MM :
am start -n com.android.settings/com.android.settings.SubSettings -e :settings:show_fragment com.android.settings.applications.RunningServices

How to get extras of currently running activity through ADB

I have a question about using ADB.
I know that this command:
adb shell dumpsys activity
can show me all the activities that are currently running on the device.
But I notice that sometimes, the intents appear like this:
Intent { ...some_intent/activity_name.... (has extras) }
I know that extras mean that the activity has been started with some sort of parameters passed to it (I may be wrong here, please correct me if I am).
So my question is, how can I get the extras of the intent/activity through ADB ?
The reason I need this is because I'm trying to launch an apk (that is installed on the phone) through ADB command, something like:
adb shell "su -c 'am start -n com.package.name/.ActivityName'"
That works and bring up the application. The application has a start screen (say we call it HomeActivity) and you have to click a button and make some selections (say SelectionActivity) and it will go to another screen (say ActionActivity). I want to be able to launch the apk and make it go straight to ActionActivity.
The application will crash if I try to launch the ActionActivity with am start command, I'm assuming this is because it requires parameters from the SelectionActivity screen.
This is why I'm trying to see what are the "extras" or parameters that the ActionActivity screen actually gets, so that I can do something like:
adb shell "su -c 'am start -n com.package.name/.ActionActivity -e param1 val1 -e param2 val2'"
Hope my question is clear.
Please correct me if I'm making a mistake somewhere.
Thanks in advance!
If I am understanding correctly, your target is to start the 'action' activity with correct intent but you don't know what kind of parameter information should be included, right?
The dumpsys command won't dump everything you want, so to simply achieve your target, you have 2 options (you should find one device which you can burn your own firmware into it):
Modify the dump method in AMS to print out more information
Modify the ActivityThread class source code to print out the detailed intent information

Categories

Resources