以下代码成功关闭数据连接。我希望警报再次点亮以重新开启。
public void triggerEnable(boolean enableData, int hourInDay, int minInDay) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, hourInDay);
calendar.set(Calendar.MINUTE, minInDay);
calendar.set(Calendar.SECOND, 0);
Intent broadcastIntent = new Intent(
"com.sang.mobiledata.IntentAction.RECEIVE_CONN_UPDATE");
broadcastIntent.putExtra("FLAG_KEY", enableData);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, broadcastIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) this
.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pi);
}
这里我调用上面的函数
triggerEnable(false, SetTimeActivity.intFromTimeH,
SetTimeActivity.intFromTimeM);
// triggerEnable(true, SetTimeActivity.intToTimeH,
// SetTimeActivity.intToTimeM);
}
我尝试使用注释行,但它不起作用。任何帮助将不胜感激!
编辑:
public class ConnBroadcastReceiver extends BroadcastReceiver {
private static final String CONN_ACTION = "com.sang.mobiledata.IntentAction.RECEIVE_CONN_UPDATE";
Network objNetwork = new Network();
@Override
public void onReceive(Context context, Intent intent) {
if(CONN_ACTION.equals(intent.getAction())) {
boolean enableConn = intent.getBooleanExtra("FLAG_KEY", false);
objNetwork.setMobileDataEnabled(context, enableConn);
}
}
}