Use Volume Key While Screen Locked
This code doesn't work will screen locked. what should I do if I want volume key work while screen locked? My code is : @Override public boolean dispatchKeyEvent(KeyEvent event) {
Solution 1:
you can register BroadcastReceiver
with action "android.media.VOLUME_CHANGED_ACTION" :
android.media.VOLUME_CHANGED_ACTION
Other way of doing is: volume key on Android .
Solution 2:
Do this in a service:
publicclassMyServiceextendsService {
@OverridepublicvoidonCreate() {
super.onCreate();
finalBroadcastReceivervReceiver=newBroadcastReceiver() {
@OverridepublicvoidonReceive(Context context, Intent intent) {
//your code here
}
};
registerReceiver(vReceiver, newIntentFilter("android.media.VOLUME_CHANGED_ACTION"));
}
}
Then register BroadcastReceiver with action Intent.ACTION_SCREEN_OFF
to play a silent sound continuously when screen is off and action Intent.ACTION_SCREEN_ON
to stop music when screen on. Volume buttons are only active when there's music playing.
Post a Comment for "Use Volume Key While Screen Locked"