【问题标题】:Click-and-hold the headset button shows no action单击并按住耳机按钮不显示任何操作
【发布时间】:2023-03-26 04:09:01
【问题描述】:

我有一个 BroadcastReceiver,我的目标是检测耳机按钮上的长按。尝试了不同的版本,没有一个工作。所以现在我正在尝试检查收到的操作。如果我正常点击,我可以看到动作 0 (KeyDown) 和 1 (KeyUp)。如果我单击并按住,无论是向下键还是向上键,都不会显示任何内容。怎么了?

@Override
public void onReceive(Context context, Intent intent) {
    if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
        KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        Log.e("action",""+event.getAction());
        ...
    }
}

如果需要,我可以发布更多代码,但我认为这无关紧要

在装有 Android 4.3 的 S4 上运行。不确定是否重要,S-Voice 已冻结,Google Now 已禁用。而且我注意到,如果我的屏幕关闭并长按,我会得到一个菜单“使用 Google 搜索/自动语音处理长按”

【问题讨论】:

    标签: android button broadcastreceiver headset


    【解决方案1】:

    我认为您可以使用清单中的这段代码来控制长按。这将打开一个对话框,让您选择要使用长按的应用程序。当手机解锁时它对我有用,但当手机锁定时它不会工作。它会弹出对话框,但当您解锁手机时它会消失。希望我能得到一些帮助。

    关键是打开“Activity”而不是实现广播接收器。

       <activity 
                android:name="packagename.activityname"
                  android:launchMode="singleInstance"
                   android:showOnLockScreen="true">
                 <intent-filter android:priority="2147483647">
                    <action android:name="android.speech.action.WEB_SEARCH" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
                <intent-filter android:priority="2147483647">
                    <action android:name="android.speech.action.VOICE_SEARCH_HANDS_FREE" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
                <intent-filter>
                    <action android:name="com.sec.action.SVOICE" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
    

    我已经在 Kitkat 上对此进行了测试。不知道以前的版本会发生什么。

    【讨论】:

      猜你喜欢
      • 2018-02-04
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 1970-01-01
      • 2015-09-26
      • 1970-01-01
      • 2021-11-26
      相关资源
      最近更新 更多