0

There are many examples of classes that extend BroadcastReceiver to be activated from another class through intent. Class is also extending from BroadcastReceiver that are activated in an event such as a received text message. My question is how to activate a class that extends BroadcastReceiver when you reach a specified time, for example 8:20 a.m. without an intent. Do not know if I explained.

JScoobyCed
  • 10,203
  • 6
  • 34
  • 58

2 Answers2

0

As mentioned in this question:

Android Alarm Manager with broadcast receiver registered in code rather than manifest

You will need to use a pendingintent for this. I am not sure why you don't want to use an intent - could you explain further?

Community
  • 1
  • 1
Emile Victor
  • 923
  • 1
  • 12
  • 22
0

I have a project where I have a unique class called AlarmReceiver and I want to display a toast at a given time, or 9:01 pm example. Specifically, the class is as follows:

package org.secure.sms;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.app.AlarmManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

 public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
     Calendar calendar = Calendar.getInstance();
  int mYear = calendar.get(Calendar.YEAR);
  int mMonth = calendar.get(Calendar.MONTH);
  int mDay = calendar.get(Calendar.DAY_OF_MONTH);
  int mHour = calendar.get(Calendar.HOUR_OF_DAY);
  int mSec = calendar.get(Calendar.MINUTE);
  if((mHour == 9 && mSec == 1) { 
    Toast.makeText(context, "Alarm Receiver message", Toast.LENGTH_SHORT).show();
  }
}
}