public static void SetWakeUpAlarmRepeating(Context context, long firstFireAfterMIliseconds)
        {
            WakeUpAlarmReceiver.CancelWakeUpAlarmRepeating(context);
            AlarmManager am     = (AlarmManager)context.GetSystemService(Context.AlarmService);
            Intent       intent = new Intent(context, typeof(WakeUpAlarmReceiver));

            pendingIntent = PendingIntent.GetBroadcast(context, 0, intent, 0);
            am.SetInexactRepeating(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + firstFireAfterMIliseconds, AlarmManager.IntervalHour, pendingIntent);
        }
Beispiel #2
0
        public override void OnReceive(Context context, Intent intent)
        {
            this.sharedPreferencesHelper = new SharedPreferencesHelper(context);
            var settingsModel = (AppSettingsModel)this.sharedPreferencesHelper.GetSharedPreference <AppSettingsModel>(SharedPreferencesKeys.APP_SETTINGS);

            if (!settingsModel.ChatDisabled && !MessengerService.ServiceIsRunning)
            {
                context.StartService(new Intent(context.ApplicationContext, typeof(MessengerService)));
            }
            WakeUpAlarmReceiver.SetWakeUpAlarmRepeating(context, 1000 * 60 * 1);
        }
        public override void OnReceive(Context context, Intent intent)
        {
            ConnectivityManager cm            = (ConnectivityManager)context.GetSystemService(Context.ConnectivityService);
            NetworkInfo         activeNetwork = cm.ActiveNetworkInfo;
            var isConnected = activeNetwork != null && activeNetwork.IsConnected;

            if (!isConnected)
            {
                WakeUpAlarmReceiver.CancelWakeUpAlarmRepeating(context);
            }
            else
            {
                //first fire after 5 sec
                WakeUpAlarmReceiver.SetWakeUpAlarmRepeating(context, 1000 * 10);
            }
        }