class ClassAlarmReceiver extends WakefulBroadcastReceiver {
AlarmManager mAlarmManager;
PendingIntent mPendingIntent;
public static final long INTERVAL = 1000 * 60 * 60 * 24;
static final long ONE_MINUTE_IN_MILLIS=60000;
@Override
public void onReceive(Context context, Intent intent) {
int mReceivedID = Integer.parseInt(intent.getStringExtra(ClassEditActivity.EXTRA_REMINDER_ID));
// Get notification title from Reminder Database
ReminderDatabase rb = new ReminderDatabase(context);
Classes classes = rb.getClasses(mReceivedID);
String mTitle = classes.getTitle();
// Create intent to open ReminderEditActivity on notification click
Intent editIntent = new Intent(context, ClassEditActivity.class);
editIntent.putExtra(ClassEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
PendingIntent mClick = PendingIntent.getActivity(context, mReceivedID, editIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//Set Alarm Ringtone
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(context, notification);
// Create Notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.app_logo))
.setSmallIcon(R.drawable.schoolbuddy_white)
.setContentTitle(context.getResources().getString(R.string.app_name))
.setTicker(mTitle)
.setContentText(mTitle)
.setSound(Uri.parse("android.resource://"
+ context.getPackageName() + "/" + R.raw.buzz_alarm))
.setContentIntent(mClick)
.setAutoCancel(true)
.setOnlyAlertOnce(false)
.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
.setLights(Color.MAGENTA, 3000,3000);
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nManager.notify(mReceivedID, mBuilder.build());
r.play();
}
Выше мой код OnReceive.Который я думаю, проблема не в этом.Но здесь:
public void setAlarm(Context context, Calendar calendar, int ID) {
mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
// Put Reminder ID in Intent Extra
Intent intent = new Intent(context, ClassAlarmReceiver.class);
intent.putExtra(ClassEditActivity.EXTRA_REMINDER_ID, Integer.toString(ID));
mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);
// Calculate notification time
Calendar c = Calendar.getInstance();
long currentTime = c.getTimeInMillis();
long afterAdding15Mins = currentTime + ( 15 * ONE_MINUTE_IN_MILLIS);
long diffTime = calendar.getTimeInMillis() - currentTime;
// Start alarm using notification time
mAlarmManager.set(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + diffTime ,
mPendingIntent);
// Restart alarm if device is rebooted
ComponentName receiver = new ComponentName(context, ClassBootReceiver.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
Я создаю приложение, которое запускает будильник раньше установленного времени.Например, если бы я установил его на 9:30, то он мог бы подать сигнал тревоги в 9:15, если пользователь установит его на 15 минут раньше времени.Пожалуйста, помогите, я не мог найти решение нигде.