【发布时间】:2016-03-23 07:45:37
【问题描述】:
检测耳机按钮双击和长按(点击)Android
我正在尝试下面的代码
public class MediaButtonReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("----onReceive--", " ");
if (Intent.ACTION_HEADSET_PLUG.equals(intent.getAction())) {
Log.e("----jack out--", " ");
if (intent.getExtras().getInt("state") == 1)// if plugged
Toast.makeText(context, "earphones plugged", Toast.LENGTH_LONG)
.show();
else
Toast.makeText(context, "earphones un-plugged",
Toast.LENGTH_LONG).show();
}
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
Toast.makeText(context, "button pressed", Toast.LENGTH_LONG).show();
// key=intent.getExtras().getString("EXTRA_KEY_EVENT");
}
abortBroadcast();
}
它检测到耳机按钮点击正确
但是我们如何检测耳机的长按和双击
【问题讨论】: