当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Is their any way to to use broadcast reciever for key event?

问题描述:

How do I use broadcast receiver for key event for example is it possible to turn on flash light by volume key without open the app or when device is locked?

public class ScreenReceiver extends BroadcastReceiver {

public static boolean wasScreenOn = true;

@Override

public void onReceive(final Context context, final Intent intent) {

if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {

// do whatever you need to do here

public boolean onKeyDown(int keyCode, KeyEvent event) {

if ((keyCode == android.view.KeyEvent.KEYCODE_VOLUME_DOWN)) {

Log.e("LightWriter", "I WORK BRO.");

}

return true;

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: