【问题标题】:Android notfication BigPictureStyle disappearing textAndroid通知大图片样式消失文字
【发布时间】:2013-10-31 17:09:31
【问题描述】:

我正在使用兼容性库实现 Android 丰富的通知,所以我的所有通知都是使用 android.support.v4.app.NotificationCompat.Builder 构建的

我使用的代码如下:

  // Base notification
  NotificationCompat.Builder b = new NotificationCompat.Builder(context);
  b.setSmallIcon(R.drawable.ic_actionbar);
  b.setContentTitle(title);
  b.setContentText(Html.fromHtml(msg));
  b.setTicker(title);
  b.setWhen(System.currentTimeMillis());
  b.setDeleteIntent(getDismissNotificationsPendingIntent(quantity));
  b.setLargeIcon(Picasso.with(context).load(iconUrl).get());

  // BigPictureStyle
  NotificationCompat.BigPictureStyle s = new NotificationCompat.BigPictureStyle();
  if (expandedIconUrl != null) {
      s.bigLargeIcon(Picasso.with(context).load(expandedIconUrl).get());
  } else if (expandedIconResId > 0) {
      s.bigLargeIcon(BitmapFactory.decodeResource(context.getResources(), expandedIconResId));
  }
  s.bigPicture(Picasso.with(context).load(bigImageUrl).get());
  b.setStyle(s);
  b.setContentIntent( // some intent
  b.addAction(R.drawable.ic_notification_ // some action
  Notification n = b.build();

  // and go ahead to show it

如果显示图像不兼容,基本上不会加载任何图像,所以我们不会无缘无故地使用内存,但这是基础,我期待类似于右侧通知的内容下图

问题是消息(在“触摸以查看您的屏幕截图”示例中)在通知收缩时显示,但在通知展开时消息消失。

有没有我忘记调用的setMessage() 方法?这是NotificationCompat 的错误吗?有人可以在这里提供一些见解吗?

【问题讨论】:

    标签: android notifications android-notifications


    【解决方案1】:

    有没有我忘记调用的 setMessage() 方法?

    是的! NotificationCompat.BigPictureStyle setSummaryText

    【讨论】:

    • 人...我怎么会错过那个?!?它只是逃过了我的眼睛。非常感谢!
    • 嗨@Budius,跳过它是如此简单,因为您的眼睛在通知上。同样的事情也发生在我身上……我很高兴 Adneal 给了我们答案。
    【解决方案2】:
     mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
     mNotificationManager.notify(0, setBigPictureStyleNotification()); 
    
    private Notification setBigPictureStyleNotification() {
        Bitmap remote_picture = null;
    
        // Create the style object with BigPictureStyle subclass.
        NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
        notiStyle.setBigContentTitle("Big Picture Expanded");
        notiStyle.setSummaryText("Nice big picture.");
    
        try {
            remote_picture = BitmapFactory.decodeStream((InputStream) new      URL(sample_url).getContent());
        } catch (IOException e) {
            e.printStackTrace();
        }
    
        // Add the big picture to the style.
        notiStyle.bigPicture(remote_picture);
    
        // Creates an explicit intent for an ResultActivity to receive.
        Intent resultIntent = new Intent(this, ResultActivity.class);
    
        // This ensures that the back button follows the recommended convention for the back key.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    
        // Adds the back stack for the Intent (but not the Intent itself).
        stackBuilder.addParentStack(ResultActivity.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);
    
        return new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setAutoCancel(true)
                .setLargeIcon(remote_picture)
                .setContentIntent(resultPendingIntent)
                .addAction(R.drawable.ic_launcher, "One", resultPendingIntent)
                .addAction(R.drawable.ic_launcher, "Two", resultPendingIntent)
                .addAction(R.drawable.ic_launcher, "Three", resultPendingIntent)
                .setContentTitle("Big Picture Normal")
                .setContentText("This is an example of a Big Picture Style.")
                .setStyle(notiStyle).build();
    }
    

    【讨论】:

    • 它只是可以在服务、广播接收器、异步任务或线程中使用的功能
    • 无需从 PHP 更改任何内容
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多