我开发了一个广播接收器,以这种方式收听清单中声明的电话信号强度
<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 没有结果(我是新手)。有什么解决办法吗?
提前致谢