で登録しService
たいBroadcastReceiver
android.net.wifi.WIFI_STATE_CHANGED
public void onCreate() {
super.onCreate();
final IntentFilter filter = new IntentFilter("android.net.wifi.WIFI_STATE_CHANGED");
MyReceiver myreceiver = new MyReceiver();
// Register the receiver so that your service will listen for broadcast
registerReceiver(myreceiver , filter);
すべてが良好で機能しますが、たとえばWi-Fiの状態が変更された後、切断された後、5分で1分間再びアクティブになり、その後再び切断されます。そして、5分後に再び1分間アクティブになりました。通常、5分後に1分間だけ接続し、再度切断します...
私はこれを試してみましたAlarmManager
が、5分後に1分間接続されてから切断する方法に問題があります。
私がやろうとしていることではない私のコード。接続されていない状態で切断されています:
AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent = new Intent(this, WifiReceiver.class);
PendingIntent pendingAlarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, alarmIntent, 0);
// start in 5 minutes and rest in 1 minutes interval
alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 5*60*1000, 1*60*1000, pendingAlarmIntent);
これどうやってするの?私はAlarmManagerの正しい方法