How to enable Stay awake in the developer options using ADB? - android

I'm trying to find a way to enable the Developer options -> Stay awake option via ADB.
The solution that I found was to find a way to open developers option menu and then enable stay awake option using setevent command in ADB.
Now I'm trying to find the command that will open the developers options.
I found the command that opens display options:
adb shell am start -n com.android.settings/.DisplaySettings
So I think that a similar command that opens developers options exists.
I will also be glad to hear about another way to enable stay awake option via ADB if there is any.

adb shell am start -n com.android.settings/.DevelopmentSettings

You can enable Stay awake option without having to use UI with the following command:
adb shell settings put global stay_on_while_plugged_in 3

OK, I found a way:
adb shell am start -S com.android.settings/.Settings\$DevelopmentSettingsActivity
I used this : https://github.com/android/platform_packages_apps_settings/blob/master/AndroidManifest.xml
to find the name of the Activity I needed.
Now I have to figure out how to choose the stay awake option by createing a touch event or something...

Set the 'keep awake while plugged in' setting.
adb shell svc power stayon true

Okay I know it is not what MiSo was asking but I think it may be relevant, I have created an app that will enable/dissable this 'Stay awake' setting as you connect/disconnect ADB.
The code is available open-source here: ABD-Stay_Awake

try this:
setprop persist.sys.usb.config mtp,adb

Related

how to enable Multi display feature on Android O

Did anyone tried Android multiple display feature which is new in Android O
Following steps which is not working for me
1.connect hdmi cable to mobile(not sure can use USB as well)
2.make device in root and give following command (expect app is installed)
and not seen that app is launching on secondary(Multiple display feature
) it's just reflecting mobile display as it is because connected hdmi cable
adb shell am start com.Chrome.Canary --display 1
Please suggest any other way or any command to make it work?
Android in general do mirroring when two displays are connected. Right now google has not enabled support for touch and display mapping on the two displays. But if you want to launch any activity on any of the two displays then the command adb shell am start "your_activity" --display display_id will launch your activity on that particular display id. If the above command doesn't launch your activity then you can use adb shell am stack start display_id "your activity". This will also work. But regarding touch, it will be mapped to the primary display (display id 0). As per google you can enable the mapping of touch in EventHub.cpp of Android source code but till now I haven't found it useful. Hope my answer helps you.
Ran using below procedure passed with dell monitor:
ADB shell can be used to call Activity Manager(am) for starting any system actions (or an activity).
The syntax:
adb shell am start [-n (component)] [-a (action)] [-t (mime type)] [-d (data_URL)]
examples:
1. For starting ‘Settings app’:
adb shell am start -n com.android.settings/.Settings
In the above-mentioned command, we set component(-n) to be settings in a specific format.
For starting ‘Gallery app’:
adb shell am start -t image/* -a android.intent.action.VIEW
In the above-mentioned command, we are setting action(-a) for opening the default app for gallery with mime type(-t) to be image/*
In general, for external display the ‘display_id’ starts from ‘1’ in an increasing order, final command to do multi display operation is
adb shell am start -n com.android.settings/.Settings --display 1
The above command will display ‘Settings’ app only in external display with display_id = 1. The primary display will be in the same mode as before executing the command.

Running shell commands on the click of a button

I wish to reset an android device programmatically using :
adb shell
recovery --wipe_data
1. What is the easiest way to do this ?
2. Will it require root/superuser access ?
For running shell commands you can use Runtime class. For more information check the documentation
For example:
Runtime.getRuntime().exec("commands_here");

Automatically forward port on start?

I need to forward a port on an android emulator, right now I had to type the command every time:
adb forward tcp:23946 tcp:23946
Is there any way to make this automatic? I tried to replace adb with a script but that command won't work until the device is up and running.
Any ideas?
Based on this answer (which I've tested and works, though it wasn't for a scenario like this one), you could simply write a script that waits until the emulator is booted.
Something like (pseudocode, don't know which platform you're on) :)
emulator #emulator-name
while ('adb shell getprop init.svc.bootanim' == "running") sleep(10s)
adb forward tcp:23946 tcp:23946

Can I use adb to change the default launcher program?

I set one of the program as default launcher program and default setting program so I cannot change the default programs now, can I change the default programs from android-sdk\android-sdk\platform-tools\adb.exe or remote shell.
How can I do that?
And can I remove the defaults of program in Java code?
For system apps you can't uninstall, use pm disable as in
adb shell pm disable com.android.launcher
you can remove (Uninstall) the default program you set using ADB by doing this :
adb uninstall app.package ..... //for example (com.example.homeapp)
If you don't want to remove the app .. here is a quick hack to do it:
adb shell
am start -a android.intent.action.MAIN
That way you will have a picker with all apps on your devices that listens to Main Action
Choose any home screen app you want . then go to settings and set it as default.
adb shell cmd package set-home-activity "package/activity"
adb reboot
The key is adb. Once you know the package name of the app you wish to clear data for, try:
adb shell pm clear package.name.of.app
It'll clear all data for the app, but I don't know of a way to only clear the defaults.
You can check and change the default sms app by using adb shell settings get secure sms_default_application and then use adb shell settings put secure sms_default_application <package name>. I'm not sure about the other default apps, but it's just a matter of finding it with adb shell settings list <secure/system/global>

How to reboot emulator to test ACTION_BOOT_COMPLETED?

Well, I have searched a lot. People say that I need to close the window of emulator to close it. However, I need to reboot the emulator to catch ACTION_BOOT_COMPLETED by my BroadcastReceiver.
How can I do that?
You can use the following command from adb:
adb shell am activity/service/broadcast -a ACTION -c CATEGORY -n NAME
for example:
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n package_name/class_name
Note that class name and package names need to be as defined in the Manifest.
This will generate the Intent you want , directed only to the component you want (otherwise you system will go crazy with BOOT_COMPLETED sent...)
Or another way (also from the command line):
adb shell stop
adb shell start
First, make sure that USB Debugging is enabled from within the emulator:
click:
the Home icon
Menu icon
'Settings'
'Applications'
'Development'
make sure that the box next to 'USB debugging' contains a check mark
from a command-line:
adb -e reboot
EDIT:
This definitely doesn't work... very strange. I tested it and could not make the emulator reboot. It just hangs.
To emulate a broadcast action, you can connect via adb to the emulator/device and open a shell:
adb shell
Then, you can broadcast the action you want to test:
am broadcast -a android.intent.action.BOOT_COMPLETED
Please note that, in the latest Android versions, broadcasting the *android.intent.action.BOOT_COMPLETED* action will actually reboot your emulator/device.
While using tubemate on android tab, I was not successful in downloading video with the error:host interupped etc. I used the following commands:
adb shell stop
adb shell start
and the application started downloading videos.
emulators have on/off button - just click it
and another way:
If you start your emulator, and select the "wipe user data" checkbox, you will also receive that notification when boot is completed.

Categories

Resources