gpt4 book ai didi

android - 手机休眠时听信号强度

转载 作者:行者123 更新时间:2023-11-30 03:45:47 25 4
gpt4 key购买 nike

<分区>

我开发了一个监听电话信号强度的广播接收器以这种方式在 list 中声明

<receiver android:name="it.cazzeggio.android.PhoneStateListener" >
<intent-filter android:priority="999" >
<action android:name="android.intent.action.SIG_STR" />
</intent-filter>
</receiver>

java代码是

public class PhoneStateListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e(PhoneStateListener.class.getSimpleName(), new Date().toString());
try{
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);

//...some checks to be sure that is a gsm-event..

GsmCellLocation location = (GsmCellLocation) telephony.getCellLocation();
foundCells.add(0,new String[] {
telephony.getNetworkOperator() + "_" + location.getLac() + "_" +
location.getCid() , ""+(bundle.getInt("GsmSignalStrength")+1)});
if(!foundCells.isEmpty())
Functions.CellHistory.addHistory(foundCells);
}catch (Exception e) {
Log.e(PhoneStateListener.class.getSimpleName(), e.getMessage(), e);
}
}

如果屏幕亮着一切正常,但是当手机进入休眠模式时我的接收器停止工作(=没有事件被发送到方法 onReceive)

我已经尝试将接收器注册为服务或使用 PARTIAL_WAKE_LOCK 而没有结果(我是新手)。有什么解决办法吗?

提前致谢

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com