这是我的MyReceiver.java类,在这里我编写了代码以显示单个通知。如何在此处创建多个通知。
public class MyReceiver extends BroadcastReceiver{
String Reqpopending;
int MID=0;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, SplashScreen.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
context).setSmallIcon(R.drawable.dashboard)
.setContentTitle("Dash Board Counts")
.setContentText("P.O Counts-532,198,654,255,901 ZeroInward-303 PartialInward-777").setSound(alarmSound)
.setAutoCancel(true).setWhen(when)
.setContentIntent(pendingIntent)
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
notificationManager.notify(MID, mNotifyBuilder.build());
MID++;
}
最佳答案
请在下面找到正在循环中运行的代码
public class MyReceiver extends BroadcastReceiver{
String Reqpopending;
int MID=0;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
for(int i = 0; i < 3; i++)
{
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, SplashScreen.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
context).setSmallIcon(R.drawable.dashboard)
.setContentTitle("Dash Board Counts")
.setContentText("P.O Counts-532,198,654,255,901 ZeroInward-303 PartialInward-777").setSound(alarmSound)
.setAutoCancel(true).setWhen(when)
.setContentIntent(pendingIntent)
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
notificationManager.notify((int)when, mNotifyBuilder.build());
}
}
希望这可以帮助。
关于java - 如何创建多个通知?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35030993/