The main Android Android application, the Broadcast Receiver onReceive () method is not called

I am working on a signaling application. I followed the Android AlarmController tutorial verbatim with some minor changes. For some reason, my onReceive () receiver is not being called when the alarm goes off. Here is the code:

// the callback received when the user "sets" the time in the dialog
private TimePickerDialog.OnTimeSetListener mTimeSetListener =
    new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

         time.set( Calendar.HOUR_OF_DAY, hourOfDay );
         time.set( Calendar.MINUTE, minute );

// Tell user alarm was set
String timeSetTo = "Alarm Set: " + time.get( Calendar.HOUR_OF_DAY ) + ":" + time.get( Calendar.MINUTE ) + " " + time.get( Calendar.AM_PM );
if( toast != null ) 
 toast.cancel();

toast = Toast.makeText( AlarmUI.this, "L" + timeSetTo, Toast.LENGTH_LONG );
toast.show();

// When the alarm goes off we want to send an Intent to our Broadcast Receiver (AlarmAction), 
// so set an Intent between the AlarmUI and the AlarmAction
Intent intent = new Intent( AlarmUI.this, AlarmAction.class );

// Create an IntentSender to have the intent executed as a broadcast later when alarm goes off.
PendingIntent sender = PendingIntent.getBroadcast( AlarmUI.this, 0, intent, 0 );

/** Schedule the alarm */
// To get any service we use getSystemService( Service Name )
AlarmManager alarmManager = ( AlarmManager ) getSystemService( ALARM_SERVICE );
/* Finally, we set the alarm to the desired time! WOOHOO! */
alarmManager.set( AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), sender );
        }
    };

Any ideas? Thank you in advance.

+3
source share
1 answer

Do you have your AlarmAction specified in your manifest?

eg. <receiver android:process=":remote" android:name=".AlarmAction"/>

+5
source

Source: https://habr.com/ru/post/1772297/


All Articles