它能够显示通知但在后台打开应用程序。当我收到通知时,我的应用程序将在后台打开,只显示通知并不打开应用程序?
PendingIntent pendingIntent;
Intent intent = new Intent(this, ExpertActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.sendmessageicon);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setLargeIcon(largeIcon)
.setSmallIcon(R.drawable.sendmessageicon)
.setContentTitle("Dummy")
.setContentText(messageBody)
.setAutoCancel(true)
.setDefaults(-1)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 , notificationBuilder.build());
@sanyasiraomopada我要开始专家活动的意图通知上点击,但应用程序在每次后台启动时我得到一个新的通知 – Ashish
可以试试这个PendingIntent contentIntent = PendingIntent.getActivity(this,0, new Intent(this,ExpertActivity.class),0); –
感谢这工作。 @GaneshGudghe – Ashish