接收音量键preSS事件时,手机处于深度睡眠 [英] Receive volume key press events when phone is in deep sleep

查看:386
本文介绍了接收音量键preSS事件时,手机处于深度睡眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想抓住音量加/减pressing事件时,手机处于深度睡眠模式。我已看过一些文章,在这里我做了什么。

在活动的onCreate 方法,我设置了 WakeLock

  PowerManager的经理=(电源管理器)this.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCKMyWakeLock);
wakeLock.acquire();
 

我已阅读,即使如果我设置此我的应用程序对事件做出响应我的屏幕被锁定。此外,我已经在增加许可的Andr​​oid清单。

 <使用-权限的Andr​​oid:名称=android.permission.WAKE_LOCK/>
 

然后在的onCreate 方法,我宣布我的广播接收器

  VolReceiver volumeBroadcastReceiver =新VolReceiver();

IntentFilter的过滤器=新的IntentFilter();
filter.addAction(android.media.VOLUME_CHANGED_ACTION);
registerReceiver(volumeBroadcastReceiver,过滤器);
 

这一切工作pretty的好那么应用程序在前台或后台,但后来我锁我的手机屏幕由pressing上的电源按钮的应用程序停止接收广播事件,我认为电源管理器必须解决这个问题,但事实并非如此。所以,请帮助我,提供一些信息。

解决方案
  

我想抓住音量加/减pressing事件时,手机处于深度睡眠模式。

根据定义,那是不可能的。

  

在活动的onCreate方法,我设置一个WakeLock

那么你是不是在睡眠模式。

  

然后我锁我的手机屏幕由pressing上的电源按钮的应用程序停止接收广播事件

这里有几种可能性。其中之一是,你的进程被终止,因为它不再需要。一旦你不再有任何前景的活动,你的过程是有资格被终止,以释放内存供其它应用程序,并可以在任何时候发生。另一种可能性是,Android的根本不发送广播,当屏幕关闭。

I'm trying to catch Volume Up/Down pressing events when phone is in deep sleep mode. I have read several articles and here what I have done.

In Activities onCreate method I set a WakeLock

PowerManager mgr = (PowerManager)this.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
wakeLock.acquire();

I have read that even if my screen is locked if I set this my application will respond to events. Also I have added permission in to Android Manifest.

<uses-permission android:name="android.permission.WAKE_LOCK" />

Then in the onCreate method I declare my Broadcast Receiver

VolReceiver volumeBroadcastReceiver = new VolReceiver();

IntentFilter filter = new IntentFilter();
filter.addAction("android.media.VOLUME_CHANGED_ACTION");
registerReceiver(volumeBroadcastReceiver, filter);

This all works pretty good then application is in foreground or background, but then I lock my phones screen by pressing on a power button application stop receiving broadcast events, I think that PowerManager must solve this issue but it doesn't. So please help me, provide some information.

解决方案

I'm trying to catch Volume Up/Down pressing events when phone is in deep sleep mode.

By definition, that is impossible.

In Activities onCreate method I set a WakeLock

Then you are not in sleep mode.

then I lock my phones screen by pressing on a power button application stop receiving broadcast events

There are a few possibilities here. One is that your process was terminated, as it is no longer needed. Once you no longer have any foreground activities, your process is eligible to be terminated to free up memory for other apps, and that can happen at any point. Another possibility is that Android simply does not send that broadcast when the screen is off.

这篇关于接收音量键preSS事件时,手机处于深度睡眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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