5

我无法使用大视图样式创建通知。支持库问题?我的代码在 Eclipse 中没问题(没有错误),但通知只显示 contentTitle、ContentText、图标……就是这样!我的通知中没有多余的行...怎么了?非常感谢你的回复 。这是代码...

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

}
4

1 回答 1

14

根据官方文档here,“只有在通知展开时才会出现大视图,这发生在通知位于通知抽屉的顶部,或者当用户用手势展开通知时”所以,为了让大视图样式,通知应放在列表顶部。

为此,当您创建通知时,请添加:

setPriority(Notification.PRIORITY_MAX)

所以它会在收到时总是放在列表的顶部(当然如果用户没有打开通知抽屉并且其他具有最高优先级的通知到达,那么不能保证你的仍然在顶部)。

于 2014-04-16T13:59:57.420 回答