Cho đến nay và nhờ trang web này, tôi đã có thể thiết lập báo thức sẽ được thiết lập và hoạt động, ngay cả khi tôi bật điện thoại.Tôi làm cách nào để thiết lập nhiều báo thức trong Android?
Bây giờ, tôi thiết lập một báo động để hiển thị một lời nhắc nhở cho sự kiện A và tôi cần các ứng dụng để thiết lập báo động khác để hiển thị khác nhắc nhở cho sự kiện B.
Tôi phải làm gì đó sai, bởi vì nó chỉ kích hoạt lời nhắc cho sự kiện A. Có vẻ như khi đã thiết lập xong, bất kỳ báo thức nào khác đều được hiểu là báo thức giống nhau. :-(
Dưới đây là chi tiết về những gì tôi đang làm theo hai bước:
1) Từ một hoạt động để thiết lập một báo động rằng tại thời điểm nhất định và ngày sẽ gọi một máy thu
Intent intent = new Intent(Activity_Reminder.this,
AlarmReceiver_SetOnService.class);
intent.putExtra("item_name", prescription
.getItemName());
intent
.putExtra(
"message",
Activity_Reminder.this
.getString(R.string.notif_text));
intent.putExtra("item_id", itemId);
intent.putExtra("activityToTrigg",
"com.companyName.appName.main.Activity_Reminder");
PendingIntent mAlarmSender;
mAlarmSender = PendingIntent.getBroadcast(
Activity_Reminder.this, 0, intent, 0);
long alarmTime = dateMgmt.getTimeForAlarm(pickedDate);
Calendar c = Calendar.getInstance();
c.setTimeInMillis(alarmTime);
// Schedule the alarm!
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, alarmTime + 15000,
mAlarmSender);
2) Từ nhận tôi gọi một dịch vụ
Bundle bundle = intent.getExtras();
String itemName = bundle.getString("item_name");
String reminderOrAlarmMessage = bundle.getString("message");
String activityToTrigg = bundle.getString("activityToTrigg");
int itemId = Integer.parseInt(bundle.getString("item_id"));
NotificationManager nm = (NotificationManager) context.getSystemService("notification");
CharSequence text = itemName + " "+reminderOrAlarmMessage;
Notification notification = new Notification(R.drawable.icon, text,
System.currentTimeMillis());
Intent newIntent = new Intent();
newIntent.setAction(activityToTrigg);
newIntent.putExtra("item_id", itemId);
CharSequence text1= itemName + " "+reminderOrAlarmMessage;
CharSequence text2= context.getString(R.string.notif_Go_To_Details);
PendingIntent pIntent = PendingIntent.getActivity(context,0, newIntent, 0);
notification.setLatestEventInfo(context, text1, text2, pIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.defaults = Notification.DEFAULT_ALL;
nm.notify(itemId, notification);
Cảm ơn trước,
monn3t
Cảm ơn bạn đã đánh cắp ... những gì bạn đề nghị đã làm các trick. Tôi đã không trả lời trước bởi vì tôi muốn đảm bảo rằng nó hoạt động đúng ... Một lần nữa cảm ơn bạn, monn3t – monn3t
@stOle: Xin hãy giúp tôi cho điều này cũng: http: // stackoverflow. com/questions/8665021/android-multiple-alarm-not-working/8665978 # 8665978 –
@ st0le: tôi có thể nhận được báo thức cho ngày và giờ khác nhau nhưng tất cả đều được phát sóng cùng một thông điệp. Làm thế nào để xử lý?Tôi muốn đặt thông báo khác nhau cho các báo thức khác nhau. . . –