19

互換性ライブラリを使用して 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ですか?ここで誰かが洞察を与えることができますか?

4

2 に答える 2

26

呼び出すのを忘れている setMessage() メソッドはありますか?

うん!NotificationCompat.BigPictureStyle setSummaryText

于 2013-10-31T17:43:45.167 に答える
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();
}
于 2014-12-31T12:09:21.580 に答える