我的广播接收器遇到问题。
我设置了早上 6 点的闹钟,它必须触发我的广播接收器,它只需要从互联网下载一些数据并进行处理。
例如,如果我将闹钟设置为下午 3 点,效果就很好。但问题是早上6点,由于没有网络连接,下载失败。
我在尝试下载之前执行部分唤醒锁定。能和这个有关系吗?手机进入深度睡眠和部分唤醒锁定是否还不够?
还能是什么?我已仔细检查以启用网络数据,并且我确实在夜间收到电子邮件和 Whatsapp。
有没有办法让 android 恢复连接?
非常欢迎任何提示或帮助!
此致,
费德里科.
My code:
BroadcastReceiver 的 OnReceive 方法:
@Override
public void onReceive(Context context, Intent intent) {
...
// acquire partial wake lock
_PowerManager.acquire();
// check internet access
if (!_Utils.isDataEnabled()){
// here is where it enters at 6am, isDataEnabled return false, so it enters here
_Log.d("_BroadcastReceiver_Synchronize:onReceive","No internet, cancel sinc");
// release partial wake lock
_PowerManager.release();
return;
}
// excecute async task that downloads data
_WebServicesGet ws = new _WebServicesGet(null, null, null);
ws.syncAll(this, false);
return;
}
_Utils.isDataEnabled:
public static Boolean isDataEnabled() {
// this method returns false at 6am
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}