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