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
Related
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?).
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 am developing an android service at OS level. ( not from SDK, its from android source code. It will be part of my custom ROM. I can tun myself as root)
I am going to give an interface to apps to do something using my custom intent. At the end I want to know who all are listening for this intent.
Is there any way to get list of all BroadcastReceiver(s) registered for a specific intent?
Thanks for help!
From a program you can use PackageManager and queryBroadcastReceivers().
From the 'adb shell', try the command:
dumpsys activity
the Activity Resolver Table lists all the things that broadcast receivers are looking for.
I am looking for a way to use ADB to dismiss the keyguard in order to automate some tasks.
I would like to start an ACTIVITY (perhaps to call the public method disableKeyguard in android.app.KeyguardManager.KeyguardLock), because I assume that it will work on all (or most) Android devices, but I am unsure of the syntax.
I do not wish to use MonkeyRunner, because it is not present (or perhaps, callable) on all devices. I also cannot send a MENU keycode (adb shell input keycode 82), because this does not dismiss the keyguard on all devices.
Currently I am sending events (low-level touch events), but this needs to be customized for each device, so it is a time consuming task.
Does anyone have a suggestion?
The "Activity Testing" article has a section called Unlocking the emulator or device that addresses this situation.
In short, there isn't a way to do it directly with adb but using disableKeyguard() isn't complicated (see the three lines of example code in the article linked to above). You could easily put together a little app that does nothing but disable the keyguard. It would then just be a matter of
adb install <apk>
adb shell am start <package>/.<activity>
# Whatever you need to automate
adb uninstall <package>
(Where <apk>, <package>, and <activity> all refer to the tiny app that just disables the keyguard.)