【问题标题】:Android service receives/intercept "home long pressed" event (similar to "Home Button Launcher")Android 服务接收/拦截“home long press”事件(类似于“Home Button Launcher”)
【发布时间】:2015-02-22 19:37:46
【问题描述】:

我正在开发一个需要接收/拦截长按主页按钮事件的应用程序。我相信这个功能可以通过广播接收器意图过滤器来实现,因为一个名为“Home Button Launcher (https://play.google.com/store/apps/details?id=com.dynamicg.homebuttonlauncher&hl=en)”的现有应用程序但我找不到任何关于如何做到这一点的相关讨论。

当安装此应用并长时间按下主页按钮(3~5 秒)时,Android 会要求用户选择需要启动的应用程序(默认的 Google 搜索或已安装的主页按钮启动器),如图https://play.google.com/store/apps/details?id=com.dynamicg.homebuttonlauncher&hl=en

有很多帖子讨论了如何在应用程序中获取主页按钮事件以了解用户何时关闭其应用程序,但没有关于如何在服务中获取此广播事件的帖子。

有谁知道我如何像主页按钮启动器那样接收/拦截此事件?

【问题讨论】:

  • hmmm,不过有这个app的源码,你懒得看了吗?
  • 感谢您的提及!!!我没有注意到有这个应用程序的源代码。我会检查它并分享他们对他人所做的方式!谢谢!
  • 我认为这是一个 ASSIST 意图
  • 是的,你是对的!!它是!非常感谢
  • 那么我可以拦截并覆盖默认的主页长按主页按钮行为并停止显示最近的应用程序对话框或谷歌搜索吗?

标签: android android-intent android-activity android-service android-broadcast


【解决方案1】:

感谢 Selvin 的提醒。唯一要做的就是在清单文件中添加这个意图过滤器:

        <intent-filter>
            <action android:name="android.intent.action.ASSIST" />
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>

【讨论】:

    猜你喜欢
    • 2012-04-20
    • 1970-01-01
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 2020-02-27
    相关资源
    最近更新 更多