Google现在不允许我的应用长时间检测耳机按钮 [英] Google now won't let my app detect headset button long click
问题描述
当用户长按(按住)耳机按钮时,我希望我的应用执行一些特定的操作.我将BroadcastReceiver
用于MEDIA_BUTTON
,并且在不运行Google Now应用以进行长按的声音操作的手机中效果很好.但是在现在自动运行Google的手机中,我的应用程序只是被忽略了.如何立即禁用Google并检测耳机按钮长按.这是我的BroadcastReceiver
类中的onReceive
方法.
I want my app to do some specific actions when user long clicks (press and hold) headset button. I use a BroadcastReceiver
for MEDIA_BUTTON
and it works fine in phones who doesn't run Google now app for sound actions for long press. But in the phones that automatically run Google now my app is just being ignored. How can I disable Google now and detect headset button long click. here is onReceive
method in my BroadcastReceiver
class.
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
return;
}
KeyEvent event = (KeyEvent) intent
.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event == null) {
return;
}
int action = event.getAction();
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_HEADSETHOOK:
/**
* for long click
*/
if (action == KeyEvent.ACTION_DOWN) {
if (!isDown) {
isDown = true;
handler.postDelayed(l, LONG_CLICK_DELAY);
}
}
if (action == KeyEvent.ACTION_UP) {
/**
* for long click
*/
if (isDown)
isDown = false;
}
break;
}
abortBroadcast();
}
推荐答案
I believe that your efforts may be in vain due to this Android bug.
我认为这会覆盖您尝试执行的所有操作,或者充其量只能启动您的应用以及Google即时....
I assume that will override anything you attempt, or at best, start your app as well as Google Now....
在等待Google修复此问题时,我只能设法在植根设备上解决此问题 sigh
I've only managed to get around this on rooted devices whilst I wait for Google to fix it sigh
这篇关于Google现在不允许我的应用长时间检测耳机按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!