0

I am aware that this question has been asked already in this site, but I could not find my answer. SO this is what i am trying ot do. My power button in my phone is not working properly. So could is there a way to override my volume up button to unlock my phone.

I am planning to implement broadcast receiver But could not find the appropriate intent-filter. Another alternative that I thought was to run a service when the screen is locked, but I am not quite sure if I can listen to key events.

So if any of the above mentioned is possible, could you hint on how to get it done or suggest another alternative?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Ashwin Surana
  • 826
  • 3
  • 10
  • 33
  • https://www.google.co.in/search?q=can+I+change+the+way+volume+button+or+power+button+works+android&oq=can+I+change+the+way+volume+button+or+power+button+works+android&aqs=chrome..69i57.12346j0j4&sourceid=chrome&espv=210&es_sm=93&ie=UTF-8 – Yauraw Gadav Dec 28 '13 at 18:55

3 Answers3

0

No, It do not think so. This can not be done.

Yauraw Gadav
  • 1,706
  • 1
  • 18
  • 39
0

There is no broadcast for volume up or down button presently. You can implement a service that will listen for any changes in the volume but it is not recommended to run a service all the time since that consumes both battery and memory.

The only solution that I can think of is using ContentObservers for listening to the changes in the settings such as volume of streams. This answer here will provide you with the code to use ContentObserver to listen for volume up or down. https://stackoverflow.com/a/7017516/1979347

Community
  • 1
  • 1
Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
0

This functionality you speak of has already been done multiple times and can be found on Google Play. However, I'm not sure how they did it, or how much their solution drains the battery.

I just did a test on my G2 (Android 4.2.2), I launched a broadcast monitor, I switched to the homescreen, and I changed the volume from there.

enter image description here

Apparently, it can detect if the volume is turned up only when it changes from silent mode > to Vibration mode > or to Sound mode. Conversely, when pressing the down volume, I think we can detect the change when it goes from the Sound Mode > to Vibration Mode > or to Silent Mode.

This is probably not what you wanted to hear, but I just wanted to confirm what the others were saying. On a non-rooted phone, what they're saying is mostly correct. On a rooted phone however, there are custom ROMs that have solved this issue.

By the way, what brand/model is your phone? On my phone, when the headset gets connected, the phone lights up. So I suppose, one could always do it the way iPhone owners do it for their phones. You'd have to cut the extremity of a head phone jack, coat half of the pin in plastic, and super glue a button on top of it to allow you to easily twist the head.

enter image description here

enter image description here

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49