Came across a problem that sometimes BluetoothLeScanner can't detect anything for about 10 or 20 seconds.
(this problem can be reproduced by running the below code multiple times, scanner will not work for a while)
bluetoothAdapter.getBluetoothLeScanner().stopScan(mScanCallback);
bluetoothAdapter.getBluetoothLeScanner().startScan(mScanCallback);
I tried to restart BluetoothLeScanner programmatically and manually turn on and off wifi + Bluetooth but it did not work, always need to wait 10 sec or so until the system detect the BLE signals.
I ended up turning airplane mode on and off, and everything works perfectly (works every time), I don't need to wait, just turn it on and off, and the system will detect the BLE signal.
What I'm trying to do is, make a button, when I click on it, the app will turn airplane mode on and off, but this seems not doable for Android 4.2 later version. Is there any way I can reproduce a similar function that works like airplane mode? (maybe be clear some cache?)
Unfortunately turning on/off Airplan mode on Android v4.2 is not supported. Have a look at the links below:-
https://developer.android.com/about/versions/android-4.2.html
How to programmatically enable/disable flight mode
Programmatically setting ON/OFF airplane mode
Is there any reason for using Android 4.2? It is a very outdated OS (10 years old) and Android has improved vastly since then especially when it comes to BLE API and functionality. If you have the option of upgrading to a newer OS, I would recommend that you start with this as your first priority.
If upgrading to a newer OS is not an option, then I would personally try to fix the actual problem instead of finding a workaround. One possibility of this happening is that you are scanning too often, which can sometimes result in no scan results being returned for about 30 seconds. This is a tricky one as the Android OS doesn't return an error - it just doesn't return any results which seems to be similar to what you are seeing. Have a look at this link and search for the string "notable scan errors". I would also look at the Logcat log as you can sometimes find more info there.
Finally, it is possible that this is somehow a problem with the hardware (especially if it is an old device). Try installing nRF Connect and scanning for BLE devices. If the issue exists over there as well, then that proves that it's a hardware/device problem. If the issue doesn't exist over there, then this is a problem with your app.
I would like to know how could I force android to stop charging at a certain level, and then re-enable charging at a lower level.Mainly, I want to avoid the overheating of the battery and always keeping the battery at 100% is not good for li-ion batteries.
Device is Samsung Galaxy Tab 2 10.1
Can it be done in /sys/class/power_supply... in modifying a certain file?
If it can be done in the kernel, what would be the files I should be looking at?
Why I want to do that?Because...
I have few of these tablets ALWAYS plugged and YES the batteries SWOLLEN and I would like to avoid this.
Thanks.
I think it can not be achieved with sysfs level.
How about some applications like task? Latest android has a new quick panel for charging. I saw it can limit to charge if you want to stop, though the TA is connected.
I think you can fix kernel charging driver, however it will definitely be a tough way...
We are working on a BLE device and have an android app to control/configure it.
The BLE connections seem to have problem with some android devices which have 4.4 updates. The connection/disconnections happen very frequently when the WiFi on the android device is ON.
When the WiFi is turned off the frequency is reduced dramatically.
Also on Nexus 5 when the WiFi is forced to use 2.4GHz, the frequency of connections/disconnections is reduced.
But the option to change the WiFi settings is not available on all phones (like Moto G).
What is the fix for this?
Any suggestions will be much appreciated.
I'm developing an app to track the users positions.
However I've found a weird behaviour of the GPS when the devices have less than 30% of battery (more or less): it stops sending info.
Does anybody know how to avoid this behaviour/find information about it?
Thank you!
UPDATE: I'm trying to find some Google's explanation about this topic. (Which is more or less the same that the flash deactivation when the battery is low). Does anybody know where can I search?
Most probably Android wants to protect the device from battery drainage, if power savings mode is enabled. On ios such an app runs untill the battery is empty.
Is there an Android API for stop charging even though physically the charging is on?
Reading previous answers, it looks like there's no way to do this exclusively in software. However, it should be relatively easy to do it with a little hardware help - i.e. by using any Bluetooth- or WiFi-enabled smart electrical switch with open API. The phone could then switch the charger on or off programmatically whenever it feels like it.
Is there an Android API for stop charging even though physically the charging is on?
AFAIK no.
Justification:
android.intent.action.BATTERY_CHANGED is a protected intent that can only be sent by the system. Therefore you cannot duplicate or override the functionality.
You guys are all missing the point - the purpose of limiting charging is to increase battery lifespan by keeping it away from fully charged conditions (and near empty but that's a different issue). If you anticipate needing a full charge then tell it to charge to 100.
If you can't set a charge limit then the battery would rarely be idle and ideally charged when on the charger. It probably requires device level support though.
https://play.google.com/store/apps/details?id=es.guille.stopcharge uses echo "0" > /sys/class/power_supply/battery/device/charge. It works for me on a nexus 4 (rooted), as long as the device isn't fully charged (in a charging state).
Also relevant: https://android.stackexchange.com/questions/15001/how-can-i-avoid-the-battery-charging-when-connected-via-usb
Contrary to some answers indicating it's not possible, it is, indeed possible with ROOT. You can find some apps on the Play Store that will allow you to do this (with root permission, of course).
The best app that works on every phone I've tried it on is Battery Charge Limit. You can download it from the Play Store or the XDA discussion thread. The app is under active development so, if you find that your phone isn't supported, just submit an issue on its GitHub page.
NB: I am not the developer of this application.
This is unfortunately not possible. Android only have read APIs for battery data.
Battery charging control is internal to the Android kernel and battery IC modules. Manufacturers do change it from time to time, like HTC is having small cycles from 95-100% (a bad idea IMO), Samsung does stop charges as soon as it reaches 100%, but I've never seen a device able to stop charging before 100% to reduce battery aging :(.
At best if we're lucky, a sysfs interface might help do that, but it requires root and will differ from device to device.
Just to add to this. Samsung phones do not stop charging after 100%. As far as I'm aware they "trickle" charge past this point however they recommend you do not charge your phone past 100% for over 1 hour. Battery manufacturers like Anker also state the same so the idea of stopping the charge at 100% would be really useful. The risks of leaving the phone on charge are battery bloat and eventually cell rupture. I wasn't aware of this to start off with an killed my samsung battery within 3 months of owning the phone.
To expand on the original question. I've noticed some kernels allow fast charging. If they are able to alter the charge rate up could we alter the charge rate down (trickle) to meet a desired finish time (when your morning alarm goes off)??
I have installed a timer on the AC receptacle where I plug my Moto E's charger into. After guestimating how much time the battery needs to charge to about 85%, I set the timer. This is not my idea of a solution, but at least it keeps my phone from being charged to 100%, as I usually err on the short side when setting the timer.
I dont think there would be such an api. If it does exist it needs to be supported by the device manufacture as its not a pure OS lever feature. The same reason would make it a bad idea to use it as not all devices will support it.
That being said it would be a bad idea to use/implement it , mobile devices are not built to directly run from the power supply and a user will not plug in the cable if he/she did not want to actually charge the device.