我如何在Android聊天应用程序中收到通知.... NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this);
nBuilder.setSmallIcon(R.drawable.app_icon_indietext);
nBuilder.setContentTitle("Notification from IndeText");
Intent nIntent=new Intent(this,ConvActivity.class);
TaskStackBuilder nStackBuilder=TaskStackBuilder.create(this);
nStackBuilder.addParentStack(ConvActivity.class);
nStackBuilder.addNextIntent(nIntent);
PendingIntent nPendingInten=nStackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
nBuilder.setContentIntent(nPendingInten);
NotificationManager nNotificationManager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nNotificationManager.notify(99999,nBuilder.build());
我在我的主要活动中使用此代码..当我们点击通知时,我想打开相同的活动
答案 0 :(得分:1)
Intent intent = new Intent(this, MainActivity.class);
intent.setData(myUri);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(intent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setAutoCancel(true)
.setContentIntent(resultPendingIntent)
.setContentTitle(notificationData.Title)
.setSound(alarmSound)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_notification))
.setContentText(notificationData.Description)
.setStyle(notiStyle).build();
答案 1 :(得分:1)
替换
PendingIntent nPendingInten=nStackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
带
PendingIntent nPendingInten= PendingIntent.getActivity(this, 0, nIntent,
PendingIntent.FLAG_UPDATE_CURRENT);