- Androidプログラミング質問スレ revision51 [無断転載禁止]©2ch.net
244 :デフォルトの名無しさん[sage]:2016/04/14(木) 22:23:18.43 ID:IUCI91sp - ヘッドセットのボタン入力を取得する方法について教えて下さい
ネットによくあるサンプル(AndroidManifest.xmlに必要な記述を行うもの)と以下の1つを試したのですがうんともすんとも取得できません。 **** ScreenReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action != null) { if (action.equals(Intent.ACTION_SCREEN_ON)) { } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { } else if (action.equals(Intent.ACTION_MEDIA_BUTTON)){ } } } }; this.registerReceiver(ScreenReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON)); this.registerReceiver(ScreenReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); this.registerReceiver(ScreenReceiver, new IntentFilter(Intent.ACTION_MEDIA_BUTTON)); **** オーバーライドしたKeyDownではボタン入力を取得できるのですが、Broadcastに関してはネットのサンプルの方は全く反応せず、 上記のものはスクリーンのオンオフしか取得できません。 必要なPermission指定等があるのでしょうか?
|