1

I am facing some problem need your help , I have my app in foreground and when i send the notification from the server , then the notification come with the notification icon .

but what i need , when my app is in foreground user is seeing the notification then notification icon should not be shown to the user.

when my app is in background/or when app is not started then notification with notification icon should come ,and user press notification icon and then notification icon get dismissed that working perfectly well.

i had tried:

if(getIntent()!=null ){
        Log.e("getIntent","getIntent");

        broadcastReciver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals(NOTIFY_ACTIVITY_ACTION ))
                {
                    if(intent.getExtras().getBoolean("reload")){

                        int notificationId = intent.getIntExtra("notificationId", 0); 
                        Log.e("notificationId","notificationId---"+notificationId);
                        NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                        manager.cancel(notificationId);

                        setFragmentView(0);

                        //finish();
                    }
                }
            }
        };
    }

In onMessageReceived:

Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("notificationId",NOTIFICATION_ID);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.splash_logo)
                .setContentTitle("Logizo")
                .setContentText("New Order Arrived")
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(NOTIFICATION_ID/* ID of notification */, notificationBuilder.build());
cpt. Sparrow
  • 415
  • 8
  • 22
Barnali Bhattacharjee
  • 497
  • 2
  • 10
  • 24

1 Answers1

0

I remove notifications icons by using following code.

 private void removeNotificationsFromStatusBar(Context context, int notificationId) {

    try {
        NotificationManager notificationManagerNS = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManagerNS.cancel(notificationId);
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(NotificationsFragment.class.getSimpleName(), "Unable to remove notification from status bar");
    }

}
Faraz Ahmed
  • 1,245
  • 1
  • 14
  • 24