Я разрабатываю приложение для Android, в котором я хочу показать новое сообщение в панели уведомлений с каждым новым уведомлением. Я могу показать уведомления в определенное время, но я хочу показать каждое уведомление с другим сообщением.Как показать другое сообщение с каждым уведомлением Android?
Ниже я вставляю код, который показывает два уведомления в указанное время. Я использовал класс диспетчера сигнализации для отображения уведомлений. MainActivity
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date(formattedDate1));
calendar.set(Calendar.MONTH, 9);
calendar.set(Calendar.YEAR, 2013);
calendar.set(Calendar.DAY_OF_MONTH, 25);
calendar.set(Calendar.HOUR_OF_DAY, 13);
calendar.set(Calendar.MINUTE, 11);
calendar.set(Calendar.SECOND, 0);
Intent myIntent = new Intent(MainActivity.this, MyReceiver.class);
myIntent.putExtra("myIntent", "Notification1");
myIntent.setType("intent1");
pendingIntent1 = PendingIntent.getBroadcast(MainActivity.this, 0,
myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(),
pendingIntent1);
Calendar calendar_new = Calendar.getInstance();
// calendar_new.setTime(new Date(, month, day))
calendar_new.set(Calendar.HOUR_OF_DAY, 13);
calendar_new.set(Calendar.MINUTE, 12);
calendar_new.set(Calendar.SECOND, 0);
Intent myIntentnew = new Intent(MainActivity.this, MyReceiver.class);
myIntentnew.setType("intent2");
myIntentnew.putExtra("myIntentnew", "Notification2");
pendingIntent2 = PendingIntent.getBroadcast(MainActivity.this, 1,
myIntentnew, 0);
alarmManager.set(AlarmManager.RTC, calendar_new.getTimeInMillis(),
pendingIntent2);
} // end onCreate
служба уведомления
private NotificationManager mManager;
Notification notification;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
}
@SuppressWarnings("static-access")
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
mManager = (NotificationManager) this.getApplicationContext()
.getSystemService(
this.getApplicationContext().NOTIFICATION_SERVICE);
Intent intent1 = new Intent(this.getApplicationContext(),
MainActivity.class);
notification = new Notification(R.drawable.ic_launcher,
"This is a test message!", System.currentTimeMillis());
intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
this.getApplicationContext(), 0, intent1,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(this.getApplicationContext(),
"We succeded", "hi!", pendingNotificationIntent);
mManager.notify(0, notification);
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
mManager.cancelAll();
}
Если кто-то может помочь мне с этим. Заранее спасибо
«Я хочу показать каждое уведомление с другим сообщением». Что ты хочешь этим сказать? Вы генерируете уведомление hardcoded или получаете его с сервера? –
на данный момент я генерирую hardcoded, –