Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Big View Notification - How to Apply Expanded Layout to Android Notification

    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 2
    • 0
    • 1.18k
    Comment on it

    There are two types of visual style which appear on the Notification, normal view and big view.

    So, here in this tutorial, we will see how to Apply Expanded Layout to Android Notification. Regarding Nig View Notification, you should aware that the Notification big view appears only when top of the notification drawer is expended by the user.

     

    Here below is an Example of small view Notification.

     

     

     

    Here below is an Example of Big view Notification.

     

     

     

     

    Here is the way to apply Expended layout to the Notification


    First, create the Object with normal view using NotificationCompat.Builder and  the big style object using NotificationCompat.BigTextStyle and after then call the Builder.setStyle() with expanded layout object as its argument.

     

           String bigText ="Android is a Linux-based operating system designed primarily for touchscreen mobile devices such as smartphones and tablet computers. Initially developed by Android, Inc., which Google backed financially and later bought in 2005,[12] Android was unveiled in 2007 along with the founding of the Open Handset Alliance:";
    
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
    
    
            NotificationManagerCompat.from(this).cancelAll();
    
            // Creates an explicit intent for an ResultActivity to receive.
            Intent intent = new Intent(this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                    Intent.FLAG_ACTIVITY_CLEAR_TASK);
    
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    
    
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.appicon_postallhere, 0)
                    .setLargeIcon(bitmap)
                    .setContentTitle("new messages normal view")
                    .setContentText(bigText)
                    .setGroup(GROUP_KEY_EMAILS)
                    .setAutoCancel(true)
                    .setGroupSummary(true);
    
            // Create the style object with BigTextStyle subclass.
            NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle()
                    .bigText(bigText)
                    .setBigContentTitle("new messages big view")
                    .setSummaryText("massages");
    
            builder.setStyle(bigTextStyle);
            builder.setPriority(NotificationCompat.PRIORITY_MAX);
    
            // This ensures that the back button follows the recommended
            // convention for the back key
            TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this);
    
            // Adds the back stack for the Intent (but not the Intent itself).
            taskStackBuilder.addParentStack(MainActivity.class);
    
            // Adds the Intent that starts the Activity to the top of the stack.
            taskStackBuilder.addNextIntent(intent);
    
    
            builder.setContentIntent(pendingIntent);
            NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
    
            notificationManagerCompat.notify(mUserNotificationId, builder.build());

     

    Big View Notification - How to Apply Expanded Layout to Android Notification

 2 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: