本文介绍了如何创建多个通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的MyReceiver.java类,并在这里,我已经写了一个code显示单个通知。如何在这里创建多个通知。
公共类MyReceiver扩展广播接收器{
串Reqpopending;
INT MID = 0;
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
// TODO自动生成方法存根
时长= System.currentTimeMillis的();
NotificationManager notificationManager =(NotificationManager)上下文
.getSystemService(Context.NOTIFICATION_SERVICE); 意图notificationIntent =新意图(背景下,SplashScreen.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 的PendingIntent的PendingIntent = PendingIntent.getActivity(上下文,0,
notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
乌里alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mNotifyBuilder =新NotificationCompat.Builder(
上下文).setSmallIcon(R.drawable.dashboard)
.setContentTitle(仪表板计数)
.setContentText(P.O计数-532,198,654,255,901 ZeroInward-303 PartialInward-777)。setSound(alarmSound)
.setAutoCancel(真).setWhen(时)
.setContentIntent(的PendingIntent)
.setVibrate(新长[] {1000,1000,1000,1000,1000});
notificationManager.notify(MID,mNotifyBuilder.build());
MID ++;}
解决方案
请在下面找到这在循环中运行的code
公共类MyReceiver扩展广播接收器{
串Reqpopending;
INT MID = 0;
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
// TODO自动生成方法存根 的for(int i = 0;我3;;我++)
{
时长= System.currentTimeMillis的();
NotificationManager notificationManager =(NotificationManager)上下文
.getSystemService(Context.NOTIFICATION_SERVICE); 意图notificationIntent =新意图(背景下,SplashScreen.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 的PendingIntent的PendingIntent = PendingIntent.getActivity(上下文,0,
notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
乌里alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mNotifyBuilder =新NotificationCompat.Builder(
上下文).setSmallIcon(R.drawable.dashboard)
.setContentTitle(仪表板计数)
.setContentText(P.O计数-532,198,654,255,901 ZeroInward-303 PartialInward-777)。setSound(alarmSound)
.setAutoCancel(真).setWhen(时)
.setContentIntent(的PendingIntent)
.setVibrate(新长[] {1000,1000,1000,1000,1000});
notificationManager.notify((INT)时,mNotifyBuilder.build());
}
}
希望这有助于。
This is my MyReceiver.java class and here i have written a code to display single notification. How to create multiple notification here.
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++;
}
解决方案
Please find below the code which is being run in the loop
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());
}
}
Hope this helps.
这篇关于如何创建多个通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!