Kris88
Kris88

Reputation: 57

I can't set Big View Styles

I can't create a notification with Big View Styles. Support library issues ? My code is ok in Eclipse (no errors) but the notification shows only the contentTitle, the ContentText, the icon...that's it ! No extra lines in my notification ... What's wrong ? Thank you so much for your reply . Here's the code...

@Override
protected void onMessage(Context arg0, Intent arg1) {
    // TODO Auto-generated method stub
    //Log.d("onMessage", String.valueOf(arg1));
    //Log.d("onMessage", "Receive a message");
    // Get the data from intent and send to notification bar
    String message = arg1.getExtras().getString("message");
    generateNotification3(arg0, message);
}


private static void generateNotification3(Context context, String message) {    
    NotificationCompat.Builder mbuilder =
            new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("lolo")
            .setContentText("text")
            .setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
            /*
             * Sets the big view "big text" style and supplies the
             * text (the user's reminder message) that will be displayed
             * in the detail area of the expanded notification.
             * These calls are ignored by the support library for
             * pre-4.1 devices.
             */
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(message));

     // Creates an explicit intent for an Activity in your app  
      Intent resultIntent = new Intent(context, Fsa.class);  

      // The stack builder object will contain an artificial back stack for  
      // the  
      // started Activity.  
      // This ensures that navigating backward from the Activity leads out of  
      // your application to the Home screen.  
      TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);  

      // Adds the back stack for the Intent (but not the Intent itself)  
      stackBuilder.addParentStack(Fsa.class);  

      // Adds the Intent that starts the Activity to the top of the stack  
      stackBuilder.addNextIntent(resultIntent);  
      PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,  
                PendingIntent.FLAG_UPDATE_CURRENT);  
      mbuilder.setContentIntent(resultPendingIntent);  

      NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);  

      // mId allows you to update the notification later on.  
      mNotificationManager.notify(100, mbuilder.build());  

}

Upvotes: 5

Views: 4545

Answers (1)

fasteque
fasteque

Reputation: 4339

According to the official documentation here, "big view appears only when the notification is expanded, which happens when the notification is at the top of the notification drawer, or when the user expands the notification with a gesture" So, in order to have the Big View style, the notification shall be placed at the top of list.

To do that, When you create your notification please add:

setPriority(Notification.PRIORITY_MAX)

so it will be placed always in the top position of the list when it is received (of course if the user doesn't open the notification drawer and other notifications with maximum priority arrive, then it's not guaranteed that yours will be still at the top).

Upvotes: 14

Related Questions