我的AlarmManager类扩展了BroadcastReceiver,我尝试了所有的东西,但它似乎从来没有收到我的警报。
这是我在主类
中的方法public void setApp(int startHour, int startMin, int endHour, int endMin) {
Intent intent = new Intent(this, AlarmManager.class);
PendingIntent sender = PendingIntent.getBroadcast(PhoneManagerActivity.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Toast.makeText(PhoneManagerActivity.this, "Start Alarm", Toast.LENGTH_LONG).show();
Calendar calendar = Calendar.getInstance();
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTimeInMillis(System.currentTimeMillis());
startCalendar.add(Calendar.SECOND, 10);
if (startCalendar.getTimeInMillis() <= calendar.getTimeInMillis()) {
startCalendar.add(Calendar.HOUR, 24);
}
Am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),AlarmManager.INTERVAL_DAY, sender);
}
这是我的接收器类
public class AlarmManager extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("beast", "alarm");
try {
Log.i("beast", "alarm recieved");
Toast.makeText(context, "Phone set",Toast.LENGTH_LONG).show();
// AdamApp3Activity adam = new AdamApp3Activity();
((PhoneManagerActivity)context).setRinger();
Intent newIntent = new Intent(context, PhoneManagerActivity.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(newIntent);
} catch (Exception e) {
Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}
我已将其定义为xml中的接收器,但它从未收到我的警报