它能够显示通知但在后台打开应用程序。
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());
答案 0 :(得分:0)
请试试这个
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ExpertActivity.class), 0);
答案 1 :(得分:-1)
试试这个
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_ONE_SHOT);