i want to launch my application when the volume turned to very low..
Edit:
Or my application should run in background and it should listen to the volume changes.. I think it sounds good...
Is it possible to do that?
Use registerMediaButtonEventReceiver with a BroadcastReceiver that handles ACTION_MEDIA_BUTTON.
This thread explains it:
Volume change listener?
Related
I just started creating apps, and now I want to know how to build something that
helps me to start an app, by execercising a volume down/up press during the sleepmode of my phone.
I think that it will need an OnReceive Method or something that works like a onclicklistener but i cant figure it out.
Greetings
In a normal way its not possible to catch your volume down/up receiver when your phone is locked(straight-forward). However here in this discussion they are trying to control volume when phone is locked via some other way - LINK
However you can launch your application when the phone is unlocked by using volume down/up event or combination using the receiver logic. You can register for "android.intent.action.MEDIA_BUTTON" to receive the broadcastreceiver.
I want to make broadcastreceiver to volume button in android.
when clicking up and down to in 3 seconds to open my aapplication.
is it possible ? if yes i will be happy to get the broadcastcode for this?
There is no BroadcastReceiver for volume up or down button presently.
Alternate may be a service but it is not recommended to run a service all the time since that consumes both battery and memory.
I want to initiate my activity anytime using Volume up/down hardware button.
I tried in some links but no use.
And also i want to know how to use service for this.
Thanks in advance..
This is not possible on Android. The Volume Buttons can't be monitored or accessed by your app unless it is the current foreground app (i.e. you have an Activity visible and in use on the screen).
An alternative could be to listen for device shake motion and start then.
i need to know in a background task if the user muted the ringer by clicking the volume button when a call is coming in. so there are 2 possible events that i could listen for:
volume button click (onKeyDown) - that would be the preferred method
ringer gets muted
it seems though that this is not possible. anyone has an idea how to accomplish that?
Thx
Simon
There are no broadcasts for exactly what you want, but you can set up a content observer to be notified when settings change (including volume). Please checkout the answer here:
Is there a broadcast action for volume changes?
Use BroadcastReceiver for this with android.media.RINGER_MODE_CHANGED
Also check AudioManager.VIBRATE_SETTING_CHANGED_ACTION ("android.media.VIBRATE_SETTING_CHANGED")
FYI: this is not possible, since the app in the foreground (the Phone app in the moment when the phone is ringing), handles the hardware button click. the event is not passed further.
I've made some research concluded that afaik I can't have an Android service for key events capture. But - maybe some will have any workaround. I have a player application, which i want to play/pause using a special button on my earphones (included for my samsung galaxy S). This is button for reciving and ending phone calls set on phones cable.
Ive tested this button - it equals KeyCode.KEYCODE_BUTTON_B const (79). And it can be handled when my player is on screen, but I'd like to play/pause also when my phone is locked (with screen off). Do You think this is possible?
For call reciving I think android uses a trick: when someone calling, the screen goes active, and the call-reciving activity can handle key events (I think - this is how it's work, but I can be wrong).
I have no idea - how to play/pause my app using this button.
I don't think there is any real good way to achieve what you want to do from the application level. However one possible solution I can come up with is this:
Listen for screen off and on Intents. When you receive SCREEN_OFF start up a "blank" activity that does nothing but listen for your button press and passes it along to your music service.
When you recieve SCREEN_ON finish() this blank activity.
I don't know for sure that this approach will work, but I used something similar to be able to listen for volume button presses while the screen was off.
Note about listening for SCREEN_OFF and SCREEN_ON intents. When I did this I had to set the filter for my receiver in java code rather than in the manifest. For some reason when I set the intent filter from the manifest it wasn't receiving those intents properly.