I understand that ADB is a powerful tool for development and testing purposes. But, I quite don't understand that how ADB can even start private components within my app that are not exported. For example, the following command shows how ADB can start an Activity within my app via explicit intent:
adb shell am start -n "<package_name>/.view.MyActivity"
MyActivity is only reachable through an explicit intent. In other words, there's no intent-filter tag defined for MyActivity in the manifest XML. On the other hand, I noticed that if start to launch a Activity which is public (meaning there's an intent-filter) and secured through a custom permission, ADB also can't start it and I get SecurityException (because ADB did't claim the permission?).
Related
Goal: So I have ADB device is rooted and I need to turn on the Vibrator motor, or Flashlight.
As an example:
adb shell am start -a android.media.action.VIDEO_CAPTURE
This launches the camera. Where can I find these actions? and how do I execute them?
Those are intents, which is a messaging object you can use to request an action from another app component.
Although intents facilitate communication between components in several ways, there are three fundamental use cases:
starting an Activity
starting a Service
delivering a Broadcast
The list of common intents can be found at https://developer.android.com/guide/components/intents-common
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/
I'm setting up a number of cellphones using adb. I have written a script which pushes the custom lockscreen and homescreen png's to the phone, specifically to the pictures folder and that works fine. I'd like to set the lockscreen and homescreen of the phone using adb if that is possible? How would I go about doing that?
This is how I would do,
Write a simple Android application with a broadcast receiver. Inside the receiver class write the methods to set the homescreen and lockscreen wallpapers. You can receive the paths for lockscreen and homescreen via the broadcast intent in onReceive() method of the receiver. Don't worry about the path for lockscreen and homescreen images. We will shortly pass it via the a broadcast intent from adb. As you already pushed the images, you will be having the path for the images.
Now from adb you can send a broadcast intent with a couple of strings for lockscreen and homescreen image path with the following command,
$ adb - s shell am broadcast - a -e lockscreen /sdcard/lockscreen.png - e homescreen /sdcard/homescreen.png
You can receive these two parameters inside onReceive via intent.getStringExtra("lockscreen") and intent.getStringExtra("homescreen")
Hope it helps. Sent from my mobile. Please let me know if something is not clear.
Setting up a broadcast receiver is unnecessary if you are okay with launching the app to set the wallpaper. I think registering the BroadcastReceiver would require you to start the app once, anyway.
You can pass a Uri to the JPEG file directly to the intent you use to start the app.
So you can set up a workflow like this.
Push the wallpaper to the device
adb push actual/path/to/wallpaper.jpg /sdcard/target-wallpaper.jpg
Start the app with an intent data Uri like follows:
adb shell am start -a android.intent.action.MAIN -n retailerservice.justbuylive.com/.MainActivity -d file:///mnt/sdcard/target-wallpaper.jpg
The file Uri can be read from the startup via getIntent() as normal from within the app.
Install and uninstall app commands are also straightforward:
adb install app-release.apk
adb shell pm uninstall package.yourcompany.com
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
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