当我收到通知我的应用程序在后台打开时,只显示通知而不打开应用程序?

时间:2016-09-14 04:42:41

标签: android android-intent push-notification android-notifications

它能够显示通知但在后台打开应用程序。

 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());

2 个答案:

答案 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);