public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            var LocationServiceIntent = new Intent ("com.ETCTimeApp.SaveLocationService");
            pendingSaveLocationServiceIntent = PendingIntent.GetService (this, 0, LocationServiceIntent, 0);
            alarm = (AlarmManager)this.BaseContext.GetSystemService (Context.AlarmService);
            //repeat every 10 minutes
            alarm.SetRepeating (AlarmType.RtcWakeup,
                10000,
                1 * 5000 * 60,
                pendingSaveLocationServiceIntent);

            var pendingIntent = PendingIntent.GetActivity (this, 1, new Intent (this, typeof(MainActivity)), 0);
            var resultString = "Location service is running on background!";

            int ic_small = Resource.Drawable.gps_small;
            var builder = new NotificationCompat.Builder (this)
                .SetAutoCancel (true)
                .SetContentIntent (pendingIntent)
                .SetContentTitle ("ETC Location Notification")
                .SetSmallIcon (ic_small)
                .SetContentText (resultString);

            // start our service foregrounded, that way it won't get cleaned up from memory pressure
            StartForeground ((int)NotificationFlags.ForegroundService, builder.Build ());

            return StartCommandResult.Sticky;
        }
        private void StartAlarm()
        {
            Context context = BaseContext;
            _alarmManager = (AlarmManager) context.GetSystemService(Context.AlarmService);
            _intentTracker = new Intent(context, typeof(GPSAlarmReceiver));
            _intentPending = PendingIntent.GetBroadcast(context, 0, _intentTracker, 0);

            var pref = GetSharedPreferences("LainLadangLainBelalang", 0);
            _jedaMenit = pref.GetInt("menitInterval", 1);

            _alarmManager.SetRepeating(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime(), _jedaMenit * 60000, _intentPending);
        }
Example #3
0
        private void StartAlarmManager ()
        {
            Log.Debug (Tag, "StartAlarmManager");

            var context = BaseContext;
            _alarmManager = (AlarmManager) context.GetSystemService (Context.AlarmService);
            _gpsIntent = new Intent (context, typeof (LokTrackerAlarmReceiver));
            _pendingIntent = PendingIntent.GetBroadcast (context, 0, _gpsIntent, 0);

            var prefs = this.GetSharedPreferences ("lok", 0);
            _intervalMinute = prefs.GetInt ("intervalMenit", 1);
            _alarmManager.SetRepeating (AlarmType.ElapsedRealtimeWakeup,
                Android.OS.SystemClock.ElapsedRealtime (),
                _intervalMinute * 60000,
                _pendingIntent);
        }