Android 手机休眠时收听信号强度
我开发了一个广播接收器,可以收听电话信号强度 以这种方式在清单中声明Android 手机休眠时收听信号强度,android,service,broadcastreceiver,wakelock,telephonymanager,Android,Service,Broadcastreceiver,Wakelock,Telephonymanager,我开发了一个广播接收器,可以收听电话信号强度 以这种方式在清单中声明 <receiver android:name="it.cazzeggio.android.PhoneStateListener" > <intent-filter android:priority="999" > <action android:name="android.intent.action.SIG_STR" /> </intent-filter>
<receiver android:name="it.cazzeggio.android.PhoneStateListener" >
<intent-filter android:priority="999" >
<action android:name="android.intent.action.SIG_STR" />
</intent-filter>
</receiver>
如果屏幕打开,一切正常,但当手机进入睡眠模式时
我的接收器停止工作(=未向方法onReceive发送任何事件)
我尝试将接收器注册为服务或使用部分唤醒锁定,但没有结果(我是新手)。有解决办法吗
提前感谢各位,在网上搜索我发现这是一个尚未解决的安卓问题: 为了节省电池,当屏幕关闭时,手机会停止更新所有收听者 关于信号强度。所以现在我放弃了 我只是做了一个愚蠢的变通办法,至少获取手机连接的手机id: 在清单中,我定义了服务
<service android:name="it.cazzeggio.android.util.OffScreenPhoneListener"/>
在OffScreenPhoneListener类中,启动“onCreate”方法
一种定时装置,用于在手机信号塔上定期重复一次检查
PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
OffScreenPhoneListener.class.getSimpleName());
if(!wakeLock.isHeld())
wakeLock.acquire();
timer=new Timer();
timer.schedule(new myTimerTask(), DELAY, DELAY);
myTimerTask扩展了TimerTask并在其方法中包含:
TelephonyManager telephony = (TelephonyManager)
getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation location = (GsmCellLocation) telephony.getCellLocation();
//Adding to my history the following infos:
// telephony.getNetworkOperator()
// location.getLac()
// location.getCid()
onDestroy方法会清除我制作的所有内容:
super.onDestroy();
timer.cancel();
timer.purge();
if(wakeLock!=null && wakeLock.isHeld())
wakeLock.release();
无论如何,感谢您的关注。好了,伙计们,在网上搜索我发现这是一个尚未解决的android问题: 为了节省电池,当屏幕关闭时,手机会停止更新所有收听者 关于信号强度。所以现在我放弃了 我只是做了一个愚蠢的变通办法,至少获取手机连接的手机id: 在清单中,我定义了服务
<service android:name="it.cazzeggio.android.util.OffScreenPhoneListener"/>
在OffScreenPhoneListener类中,启动“onCreate”方法
一种定时装置,用于在手机信号塔上定期重复一次检查
PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
OffScreenPhoneListener.class.getSimpleName());
if(!wakeLock.isHeld())
wakeLock.acquire();
timer=new Timer();
timer.schedule(new myTimerTask(), DELAY, DELAY);
myTimerTask扩展了TimerTask并在其方法中包含:
TelephonyManager telephony = (TelephonyManager)
getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation location = (GsmCellLocation) telephony.getCellLocation();
//Adding to my history the following infos:
// telephony.getNetworkOperator()
// location.getLac()
// location.getCid()
onDestroy方法会清除我制作的所有内容:
super.onDestroy();
timer.cancel();
timer.purge();
if(wakeLock!=null && wakeLock.isHeld())
wakeLock.release();
无论如何,感谢您的关注。您的BroadcastReceiver类的代码是什么?你能发布你的PhoneStateListener类代码吗?你的BroadcastReceiver类的代码是什么?在这里包括它。你能发布你的PhoneStateListener类代码吗