報警管理:
報警管理器沒有任何與顯示狀態,所以是它可以工作,即使屏幕關閉。
網絡Avaiability片段:
public boolean isNetworkAvailable() {
Context context = getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
boitealerte(this.getString(R.string.alert),"getSystemService rend null");
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
如果不是(飛行模式,夠不着,等等)
不要這個功能將網絡是否可用,假返回true別忘了在您的清單
一個可能的解決方案添加權限
曾經作過類似下面的事件廣播的接收器屏幕關閉&屏幕,
public class ScreenReceiver extends BroadcastReceiver {
public static boolean wasScreenOn = true;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
// do whatever you need to do here
wasScreenOn = false;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
// and do whatever you need to do here
wasScreenOn = true;
}
}
}
在這種接收器給邏輯請求,如果網絡可用..
這是一個開端,何談其他問題? – 2011-12-23 17:19:55
我很快就會加入他們,這將是一個長的答案... – 2011-12-23 17:21:06
我已經更新了我的答案。你需要更多信息 ? – 2011-12-23 17:28:37