我怎样才能收到在休眠模式下的硬件关键事件? [英] How I can receive hardware key events in sleep mode?

查看:131
本文介绍了我怎样才能收到在休眠模式下的硬件关键事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序,使人们处于危险中拨打911。

这是它应该如何工作的:

  1. 在他(或她)觉得危险。
  2. 在他推动音量向下键三次。
  3. 在我的应用程序调用911。

但我面临着以下问题:我怎么能接受hardward关键事件的在睡眠模式下

我已经搜索谷歌和其他搜索引擎,但无法找到任何有关。

解决方案

 公共类YourBoardcastReceiver扩展的BroadcastReceiver {
        @覆盖
        公共无效的onReceive(上下文的背景下,意图意图){
                如果(Intent.ACTION_CAMERA_BUTTON.equals(intent.getAction())){
                        主要意图=新的意图(); //
                }
        }
}
 

而在你的清单:

 <接收器的Andr​​oid版本:NAME =YourBoardcastReceiver>
                <意向滤光器>
                        <作用机器人:名称=android.intent.action.SCREEN_ON/>
                &所述; /意图滤光器>
< /接收器>
 

I'm writing an application that allows people in danger to call 911.

This is how it should work:

  1. He (or she) feels danger.
  2. He pushes the volume-down key three times.
  3. My app calls 911.

But I'm facing the following problem: how can I receive a hardward key event in sleep mode?

I've searched Google and other search engines, but can't find anything related.

解决方案

public class YourBoardcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
                if (Intent.ACTION_CAMERA_BUTTON.equals(intent.getAction())) {
                        Intent main = new Intent();// 
                }
        }
}

And in your Manifest :

<receiver android:name="YourBoardcastReceiver">
                <intent-filter>
                        <action android:name="android.intent.action.SCREEN_ON" />
                </intent-filter>
</receiver>

这篇关于我怎样才能收到在休眠模式下的硬件关键事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆