您好我正在处理Android中的推送通知,它工作正常,但问题是每个新的电子邮件通知状态栏中都会显示单独的通知图标。我只想显示多封邮件的单个图标,请向我推荐解决方案。我将在下面发布我的代码。先感谢您.....!
int icon = R.drawable.app_icon;
long time = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent;
if(event.equals("1"))
{
i++;
try{
String msg;
if(!full_name.equals("") || !full_name.equals("null"))
{
msg="New ticket created by "+full_name+"";
}
else
{
msg="New ticket created by client ("+i+")";
}
notificationIntent = new Intent(context,Ticket_Tabs.class);
notificationIntent.putExtra("filter_id","&vis_filter_id=1");
notificationIntent.putExtra("title",(String)context.getString(R.string.inbox));
notificationIntent.putExtra("client_id",client_id);
notificationIntent.putExtra("dept_id",department_id);
notificationIntent.putExtra("set_queue","no");
notificationIntent.putExtra("Ticket_hash",hash);
notificationIntent.putExtra("Ticket_id",ticket_id);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_NEW_TASK);
String x_id = UUID.randomUUID().toString();
notificationIntent.putExtra("x_id", x_id );
notificationIntent.setAction(x_id);
PendingIntent pending_intent =PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setWhen(time)
.setContentTitle((String)context.getString(R.string.app_name))
.setContentText(msg)
.setSmallIcon(icon)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_VIBRATE| Notification.DEFAULT_SOUND)
.setContentIntent(pending_intent);
Notification notification=notificationBuilder.build();
notificationManager.notify(i, notification);
}
catch(Exception e)
{
Log.d("Exception in Notification : ",e.toString());
}
}
答案 0 :(得分:0)
int icon = R.drawable.app_icon;
long time = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent;
if(event.equals("1"))
{
i++;
try{
String msg;
if(!full_name.equals("") || !full_name.equals("null"))
{
msg="New ticket created by "+full_name+"";
}
else
{
msg="New ticket created by client ("+i+")";
}
notificationIntent = new Intent(context,Ticket_Tabs.class);
notificationIntent.putExtra("filter_id","&vis_filter_id=1");
notificationIntent.putExtra("title",(String)context.getString(R.string.inbox));
notificationIntent.putExtra("client_id",client_id);
notificationIntent.putExtra("dept_id",department_id);
notificationIntent.putExtra("set_queue","no");
notificationIntent.putExtra("Ticket_hash",hash);
notificationIntent.putExtra("Ticket_id",ticket_id);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_NEW_TASK);
String x_id = UUID.randomUUID().toString();
notificationIntent.putExtra("x_id", x_id );
notificationIntent.setAction(x_id);
PendingIntent pending_intent =PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setWhen(time)
.setContentTitle((String)context.getString(R.string.app_name))
.setContentText(msg)
.setSmallIcon(icon)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_VIBRATE| Notification.DEFAULT_SOUND)
.setContentIntent(pending_intent);
if(i!=0)//THIS ONE FOR THE SINGLE LOGO IN THE NOTIFICATION
{
notificationBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
}
Notification notification=notificationBuilder.build();
notificationManager.notify(i, notification);
}
catch(Exception e)
{
Log.d("Exception in Notification : ",e.toString());
}
}