1
我已经开发了广播接收器侦听以这种方式在清单中声明的手机信号强度 听signalStrength当手机睡觉
<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没有结果(我是一个新手)。任何解决方案
在此先感谢
你的BroadcastReceiver类的代码是什么?包括在这里。 – 2013-02-23 11:00:35
你能发布你的PhoneStateListener类代码吗? – Riskhan 2013-02-23 11:09:41