I'm trying to change in my emulator the battery status as capacity and ac status but isn't working.
I made the whole steps:
1) Connected to the emulator via telnet;
2) Tried to use the commands such power ac off and power capacity 70
3) Every time I checked the power display, the same configuration appears and no change I input is save, and the emulator always show the battery with a "!".
FR I saw this link Change emulator battery level in Windows, tried it and nothing resolved.
Follow my data about the battery:
power display
AC: online
status: Not charging
health: Dead
present: false
capacity: 0
Thank you!
It seems like your emulator device has battery option turned off.
You can change AVD battery configuration through:
Open AVD configuration file:
Default location for Linux/MAC
~/.android/avd/<AVD name>.avd/config.ini
Default location for Windows XP
C:\Documents and Settings\<user>\.android\avd\<AVD name>.avd\config.ini
Default location for Windows Vista and later
C:\Users\<user>\.android\avd\<AVD name>.avd\config.ini
Change the line:
hw.battery=no
to
hw.battery=yes
You made right. I did it on my computer and sometimes it did not worked too, I just had to set battery status to discharging before setting its capacity.
power status discharging
Additionally there is a nice tutorial that could help you with additional commands:
http://www.stealthcopter.com/blog/2010/07/changing-the-battery-percentage-in-an-avd-android-virtual-device-emulator/
Related
I am working on Preferred Network Mode Settings in AOSP code. I have to change the network mode to 4g, 3g or 2g based on selection from the UI without switching on/off Airplane mode or rebooting the device.
For 2g scenario I am setting NETWORK_MODE_GSM_ONLY by setting networkmode to '1'. But still whenever I select 2G, It shows 'E' in the status bar icon and changes to '3G' in just 1 or 2 seconds.
mTelephonyManager.setPreferredNetworkType(mSubId, 1);
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.PREFERRED_NETWORK_MODE + mSubId, 1)
I even tried in phone settings on typing *#*#4636#*#*, selecting 'GSM only' there, then also the behavior is same. The behavior is same even after turning on/off Airplane mode or rebooting the device.
Please Let me know if anyone has seen any issue like this, and where i might be going wrong.
I tried this command "adb shell settings list global | findstr preferred" and below was the output
preferred_network_mode1=1
preferred_network_mode=9
I even tried from adb using "adb shell settings put global preferred_network_mode 1" but didn't help.
later the output was
preferred_network_mode1=1
preferred_network_mode=1
But there was no change in behavior.
Please help me in understanding why this issue is occuring and Kindly enlighten me with what is difference between preferred_network_mode, preferred_network_mode1 and preferred_network_mode2.
I am trying to find if I can enable and/or disable Android's built-in "Battery Saver" mode programmatically.
Any official approaches, or trickery, are welcome.
For reference, here is how to do it following Android's standard UI in 5.0:
http://www.androidcentral.com/android-50-lollipop-basics-how-get-more-life-between-charges-battery-saver
I am aware you can detect it -- that is not what I am after.
Thanks all.
You can enable/disable Battery Saver programmatically on rooted devices. You have to edit the low_power value in global table, in /data/data/com.android.providers.settings/databases/settings.db file.
If your device supports settings command, you can execute (as root):
settings put global low_power 1
to enable Energy Saver and
settings put global low_power 0
to disable it.
If it doesn't, use sqlite3 command:
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "update global set value='1' where name='low_power';"
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "update global set value='0' where name='low_power';"
Remember that you have to unplug your phone from PC first, otherwise system will disable Energy Saver. Use ADB over WiFi or Android Terminal (Emulator).
UPDATE:
The sqlite3 method doesn't seem to be reliable anymore.
I'm not sure if android.os.action.POWER_SAVE_MODE_CHANGED broadcast gets send. Maybe you have to send it manually, like in code from here:
private static String COMMAND_ENABLE = "settings put global low_power 1\n" +
"am broadcast -a android.os.action.POWER_SAVE_MODE_CHANGED --ez mode true\n";
private static String COMMAND_DISABLE = "settings put global low_power 0\n" +
"am broadcast -a android.os.action.POWER_SAVE_MODE_CHANGED --ez mode false\n";
Also, it's been reported that a new power_saving entry appeared in settings database, however in Android 6.0.1 I haven't managed to find it. In Android 7.1.1_r13 low_power is still used internally (e.g. here), however it may get changed in some Android release. You may want to keep checking changes in e.g. this and this file.
You cannot without rooting your phone. I am not sure why this is the case, especially where location services are required now for viewing scan results since SdkVersion 23+ .
This issue is very revealing.
https://code.google.com/p/android/issues/detail?id=185370
The best answer is application developers are being forced to crowd source network location for their google overlords. Notice, the OS itself has no problem displaying scan results without location services on.
Revealing that there is no way to turn on location services without GPS where location services are inactive. This two step shuffle is a major quality of experience issue for users. Turn location services on, then turn GPS off.
Watch this space, more lock downs on the way.
I need to access to programmatically turn ON & OFF Power Saving Mode in android.
Is there any API for this ? As I can see Power Saving mode option is not available
for all mobile devices, is there any code to check these settings availability and if available then turn it ON and OFF ?
Also is there any work around ?
If you want to test the Power Saving Mode (PSM):
The following works with Android Studio 3.4.1 and a Google Pixel 2 XL phone:
$ adb shell dumpsys battery unplug # a charging device cannot enter PSM
$ adb shell settings put global low_power 1 # enter Power Saving Mode (PSM)
This only works on devices that has the standard Power Saving Mode, like Samsung's, but not Huawei's, for example. On some Samsung devices, this setting is stored in global setting keyed psm_switch, as mentioned above.
You can leave PSM by setting low_power to 0 or by enabling charging again with:
$ adb shell dumpsys battery reset
Source: https://developer.android.com/training/monitoring-device-state/doze-standby#testing_doze_and_app_standby
It's bad practice to control the user's device settings from your app.
Rather consider suspending background services when battery levels are low.
Or to notify the user of low battery power and advising the user to switch of unnecessary settings like Bluetooth or WiFi.
Most devices won't have a built-in power-saver API, so you could try to make your own power-saver mode by turning off the bluetooth if it's on, the wi-fi, etc, deactivating location in settings, or checking for other power-eating options enabled.
There are no available API's to do this in android SDK. however You can control/save the power by Turning off Blutooth,Wi-Fi and other unused sevices inside your coding.
You can't set the power saving mode programmatically. Allowing this would be a bad idea.
On certain Samsung devices you can check if it is enabled:
final String result = Settings.System.getString(getContentResolver(), "psm_switch");
Log.v("Debug", "Powersaving active: " + TextUtils.equals(result, "1"));
See this for more info: https://stackoverflow.com/a/39296959/3600178
DDMS is not able to send location to the emulator. I have tried sending just the location from DDMS but still the emulator is not able to receive location. The application works properly in the device but its not able to capture location data in the emulator.
I am testing on Android 2.2 emulator. Can anyone let me know what can be the issue?
Make sure your AVD has GPS support hardware set to true
Create New AVD > Hardware > New > GPS support
Value should be "yes"
Also, ensure your app is requesting location updates in some way, otherwise the emulator will just ignore any incoming locations from DDMS or the console.
I just use the android console via telnet, it always works.
Just open a command line and:
telnet localhost 5554
5554 is the port number of your emulator, it is usually that but might change, it can be on the window fram of the emulator as PORT:AVD_NAME.
You should be greeted with an Android console message.
To send positions to your device just type.
geo fix []
Two valid statements would be
geo fix -77.036519 38.896143
geo fix -77.036519 38.896143 100
Hope this helps, its not DDMS, but it works always. You can also feed it nmea sentences but I dont think you need that.
I don't know what your setup looks like, but I've had problems sending locations via DDMS using Windows XP and regional settings set to Swedish. Changing the regional settings to English(USA) solves the problem for me. I guess it has something to do with how numbers are formatted. With swedish settings numbers are formatted as 123 456 789,00 and with English(USA) as 123,456,789.00. Hope it helps
I had this problem and I resolve it by disabling the firewall,
hope it works for you.
In order to generate the notifications i need to know about how to generate the low battery and low memory interrupts programmatically. Can any one please provide your suggestions.I am aware of Intents.
To trigger your onTrimMemory callbacks:
adb shell am send-trim-memory <process-name> <level>
e.g. adb shell am send-trim-memory com.example.app MODERATE
Low memory can also be simulated using Background process limit under the device developer options.
Go to Settings > Developer options. Under the app section change the Background process limit to No background processes
Now your activity will be killed every time you switch to another app. Useful for testing state saving and state restoration.
yes, this api triggers the same callback you would get if you registered a context to ComponentCallback2, specifically the ComponentCallback2#onTrimMemory this wasn't mentioned here, so I thought I'd make it clear. The syntax for this command is:
am send-trim-memory [--user <USER_ID>] <PROCESS> [HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE|RUNNING_CRITICAL|COMPLETE]
Note: this command is only available on devices running Marshmallow+
On the Android Emulator you can set the power status by connecting to the Emulator console and using the power command.
As far as low memory goes, you just need to make sure that your application can handle being killed without warning when it is in the background. Testing this is one of the very few cases that actually call for a Task Manager on Android, or if you're running Android 2.2 you can kill applications via Settings.
There are ways of reducing the memory available to applications but I think they're unnecessary.
To simulate low Battery warning, try this command in the way answered by Frank:
power capacity 10 // It will set the battery level into 10%
For low Memory:
ulimit -Sv 15000 //The current memory limit will set to 15000 Kb
You can use the emulator menu. Just telnet to localhost on the port of your emulator (default is 5554) and then type help. Follow the instructions from there!
To trigger the memory trim event, an app can be used that fills all the RAM of the device, and that triggers the event.
There are many on the Play Store, they can be found by searching for 'fill ram'.