gpt4 book ai didi

java - 如何创建多个通知?

转载 作者:行者123 更新时间:2023-11-29 20:10:33 25 4
gpt4 key购买 nike

这是我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com