按键监听
来源:互联网 发布:android 美团外卖源码 编辑:程序博客网 时间:2024/05/17 07:33
home键:
public static BroadcastReceiver mHomeKeyEventReceiver = new BroadcastReceiver() { //监听home键,如果按了home键则退出长截屏模式 String SYSTEM_REASON = "reason"; String SYSTEM_HOME_KEY = "homekey"; String RECENT_APPS = "recentapps"; @Override public void onReceive(Context context, Intent intent) { Tools.log(TAG, "mHomeKeyEventReceiver onReceive "); if (mScreenService.isSavingPicture) { Tools.log(TAG, "mHomeKeyEventReceiver onReceive mScreenService.isSavingPicture==true now return"); return;} String action = intent.getAction(); Tools.log(TAG, " intent.getAction(); =====" + intent.getAction()); if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) { String reason = intent.getStringExtra(SYSTEM_REASON); Tools.log(TAG, " intent.getStringExtra(SYSTEM_REASON) == " + intent.getStringExtra(SYSTEM_REASON)); if (TextUtils.equals(reason, SYSTEM_HOME_KEY)) { //表示按了home键,程序到了后台 Tools.log(TAG, "mHomeKeyEventReceiver onReceive Home clicked stopSelfBySelf"); mScreenService.stopSelfBySelf(); }else if (TextUtils.equals(reason, RECENT_APPS)) { Tools.log(TAG, "mHomeKeyEventReceiver onReceive recent apps clicked stopSelfBySelf"); mScreenService.stopSelfBySelf();} } } }; public static BroadcastReceiver PhoneStatReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { //如果是拨打电话 if(intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)){ // incomingFlag = false; String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); }else{ //如果是来电 TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE); switch (tm.getCallState()) { case TelephonyManager.CALL_STATE_RINGING: if (mScreenService.isSavingPicture) { Tools.log(TAG, "phoneStatReceiver call is comming mScreenService.isSavingPicture=="+mScreenService.isSavingPicture); return; } Tools.log(TAG, "phoneStatReceiver call is comming stopSelfBySelf"); mScreenService.stopSelfBySelf(); } } } } ;
熄屏监听:这个只能动态注册才能接收到
/** * Broadcast Action: Sent when the device goes to sleep and becomes non-interactive. * <p> * For historical reasons, the name of this broadcast action refers to the power * state of the screen but it is actually sent in response to changes in the * overall interactive state of the device. * </p><p> * This broadcast is sent when the device becomes non-interactive which may have * nothing to do with the screen turning off. To determine the * actual state of the screen, use {@link android.view.Display#getState}. * </p><p> * See {@link android.os.PowerManager#isInteractive} for details. * </p> * You <em>cannot</em> receive this through components declared in * manifests, only by explicitly registering for it with * {@link Context#registerReceiver(BroadcastReceiver, IntentFilter) * Context.registerReceiver()}. * * <p class="note">This is a protected intent that can only be sent * by the system. */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
public static BroadcastReceiver ScreenOffReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { //如果虚拟来电 if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { if (mScreenService.isSavingPicture) { Tools.log(TAG, "FakeCall is comming mScreenService.isSavingPicture=="+mScreenService.isSavingPicture); return; } Tools.log(TAG, "Screen off stopSelfBySelf"); mScreenService.stopSelfBySelf(); } } } ;
0 0
- 按键监听
- 按键监听
- Android 按键的监听
- 如何监听home按键
- 监听android home按键
- Android监听HOME按键
- Android监听HOME按键
- Android监听HOME按键
- Jquery监听组合按键
- android 键盘按键监听
- 如何监听音量按键
- 监听HOME按键
- Android如何监听按键
- Android监听HOME按键
- 如何监听home按键
- Android耳机按键监听
- android home按键监听
- android--监听按键
- Linux下安装Lnmp环境之Mysql(二)
- mysql插入中文乱码问题
- 表单取消监听数据变化
- 优秀设计师不得不知道的用户体验设计(一)
- npm init node 通过指令创建一个package.json文件及npm安装package.json
- 按键监听
- Springboot 中filter 注入对象
- Fragment总结
- 二分求根及牛顿迭代求根分析
- 图 数据结构
- iOS之Sizeclass简介
- python元类
- Java核心技术Ⅰ笔记
- 环信SDK 头像、昵称、表情自定义和群聊设置的实现 二(附源码)