0

My problem is that when i receive any notification in my application, notification icon is shown at top bar like in following picture. In the marked area you can see that i have received the notification icon, so to see the notification of app i have to drag down the screen but in many apps i have seen that if user is using mobile and whenever notification is received from any app a small popup is shown at top of mobile screen attached to mobile top. I also want the same thing for notifications of my app

Now I want that whenever I receive notification it should be shown on top of screen like this by default instead of just showing icon in the top, so that I myself didn't have to drag screen from top to see new notification

my code for generation notification is as following

case GCM_NOTIFY_VIDEO_COMMENT: {

                if (App.getInstance().getId() != 0 && Long.toString(App.getInstance().getId()).equals(accountId)) {
                    callNotificationBadge(context);
                    App.getInstance().setNotificationsCount(App.getInstance().getNotificationsCount() + 1);

                    message = context.getString(R.string.label_gcm_comment);

                    NotificationCompat.Builder mBuilder =
                            new NotificationCompat.Builder(context)
                                    .setSmallIcon(R.mipmap.ic_launcher)
                                    .setContentTitle(title)
                                    .setContentText(message);

                    Intent resultIntent = new Intent(context, NotificationsActivity.class);
                    resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);


                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                        showNotificationForOreo(context,title,message,resultIntent,CHANNEL_social_ID,CHANNEL_social_Name);
                        break;
                    }

                    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
                    stackBuilder.addParentStack(NotificationsActivity.class);
                    stackBuilder.addNextIntent(resultIntent);
                    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
                    mBuilder.setContentIntent(resultPendingIntent);
                    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                    mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
                    mBuilder.setAutoCancel(true);
                    mNotificationManager.notify(0, mBuilder.build());
                }

                break;
            }
Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
umair_aziz
  • 51
  • 1
  • 7
  • Have a look https://stackoverflow.com/questions/29949501/android-show-notification-with-a-popup-on-top-of-any-application & find more here [official document](https://developer.android.com/guide/topics/ui/notifiers/notifications) – Mohamed Mohaideen AH Sep 10 '18 at 08:44

0 Answers0