turn on /off hardware key light (Home, Menu, Back) - android

In my application i want to turn on /off the hardware key back light(Home, Menu, Back) programatically.I searched many more but they will work on rooted device but i want for all whether its rooted or not.Can any one tell me that how can i do that.

I got the below answer that is working perfactly
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK ,
"My wakelook");
wakeLock.acquire();
to release wakelock used below code
wakeLock.release();

Related

turn on screen from service

I have Android 7 (API 24). I launch my app which launches started service. Then timeout causes screen to turn off. The service does something in background and eventually wants to turn the screen back on. How can I turn the screen on from service?
I already tried:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "MyApp::MyWakelockTag");
wl.acquire();
The permission for WAKE_LOCK was set. I also wanted to use FULL_WAKE_LOCK flag, but this is deprecated. Anyway, this doesn't work.
I also tried to launch my activity from service and implement this in OnResume of my activity:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
This also doesn't work (i.e. it doesn't turn the screen on).
Thank you for your help.

Poking the Android PowerManager (like if the user had just interacted with it)

I have an external device connected to an android tablet. I would like that interactions with this external device have the same effect on power management that if the user interacted directly with the tablet.
In other words, I'm looking for a way to reset the sleep countdown without holding a full wakelock on the device.
I've found a way, but it's a bit twisty and there ought to be something more official: I take a wakelock and release it right away!
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
WakeLock wakelock = pm.newWakeLock((PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP |
PowerManager.ON_AFTER_RELEASE), TAG);
wakelock.acquire();
wakelock.release();
Any better way to do this?

Android Device screen not turning off

I started songs on one of the music apps, on my android device.
Although I can see only partial wake_locks being acquired, still device display doesn't turn off even after screen timeout.
I wonder what is keeping the device screen on.
Can someone suggest where to look for probable cause.
Thanks!
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock(
pm.SCREEN_DIM_WAKE_LOCK, "My wakelook");
// This will make the screen and power stay on
// This will release the wakelook after 1000 ms
wakeLock.acquire(1000);
// Alternative you can request and / or release the wakelook via:
// wakeLock.acquire(); wakeLock.release();
I used this code and works fine to me.

Android - Disable proximity sensor in my app

I'm working on an app that allows the user to start a phone call from the app itself and once the call was initiated, the user can get back to the app to do some UI actions.
My current problem is that once the call started the proximity sensor was enabled which makes it almost impossible to work with the app (depends on the sensitivity of the sensor - per device).
Is there anyway to control the sensor?
For example, I would like to disable the sensor once my activity is visible and re-enable it once invisible.
Thanks,
Lior.
Try to set WakeLock in your application code...like below....
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK, "FullWakeLock" );
Hope it will help you...

Running a Android App while the screen is black

I'm trying to run a android app while the screen is black, i used a service and i tryed to add also a WakeLock of the type "PARTIAL_WAKE_LOCK".
The service play a song and save data from the accelerometer to the db, but when i press the red phone button to make the screen black, it play the song but it don't save data to the db. Have anyone a idea of why it don't save data to the db?
Tnk's
Valerio
With this you ensure that the code between acquire() and release() are executed even if the phone is in stanby mode, since the cpu will stay active.
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
wl.acquire();
..CPU will stay on during this section..
wl.release();

Categories

Resources