问题描述:

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;

}

相关阅读:
Top