コード例 #1
0
        public static void CancelPendingAlarm(this Context that, Class IntentClass)
        {
            // http://stackoverflow.com/questions/6522792/get-list-of-active-pendingintents-in-alarmmanager
            var myIntent      = new Intent(that, IntentClass);
            var pendingIntent = PendingIntent.getService(that, 0, myIntent, 0);


            AlarmManager alarmManager = (AlarmManager)that.getSystemService(Context.ALARM_SERVICE);

            alarmManager.cancel(pendingIntent);
        }
コード例 #2
0
        // http://stackoverflow.com/questions/6274141/trigger-background-service-at-a-specific-time-in-android
        // http://stackoverflow.com/questions/7144908/how-is-an-intent-service-declared-in-the-android-manifest
        // http://developer.android.com/guide/topics/manifest/service-element.html


        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            ScrollView sv = new ScrollView(this);

            LinearLayout ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);

            sv.addView(ll);



            #region startservice
            var startservice = new Button(this).WithText("Start Service to send Notification").AtClick(
                delegate
            {
                this.ShowToast("start");

                var myIntent       = new Intent(this, typeof(MyAlarmService).ToClass());
                this.pendingIntent = PendingIntent.getService(this, 0, myIntent, 0);

                AlarmManager alarmManager = (AlarmManager)this.getSystemService(ALARM_SERVICE);



                alarmManager.set(AlarmManager.RTC, 1000 * 5, this.pendingIntent);
            }
                );
            ll.addView(startservice);
            #endregion

            #region stopservice
            var stopservice = new Button(this).WithText("Stop Service").AtClick(
                delegate
            {
                this.ShowToast("stop");

                AlarmManager alarmManager = (AlarmManager)this.getSystemService(ALARM_SERVICE);

                alarmManager.cancel(this.pendingIntent);
            }
                );

            ll.addView(stopservice);
            #endregion



            this.setContentView(sv);

            //this.ShowToast("http://jsc-solutions.net");
        }