【问题标题】:Notification with BigPicture, Large and Small Icon带有大图片、大图标和小图标的通知
【发布时间】:2015-10-13 09:39:23
【问题描述】:

我有两种方式的通知实现: 1.大图标+小图标(标题+留言) 2. LargeIcon + SmallIcon +Big Pictuire.(Title+ Message+ Message2(PicURL) )

第一个工作正常,大图标和小图标显示在右下角。

对于第二个实现。我可以看到大图+小图标。 但是只有当我在通知中展开大图片时,我才会看到大图标。 如何在通知上显示带有大图片的 LargeIcon + Small Icon?

代码如下:

private void sendNotification(String title, String msg, String msg1) {
    Log.i("msg1", "" + msg1);
    NotificationCompat.BigPictureStyle s = new NotificationCompat.BigPictureStyle();

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

    Context context = getApplicationContext();
    Intent myIntent = new Intent(context, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(
            context,
            0,
            myIntent,
            PendingIntent.FLAG_ONE_SHOT); //Intent.FLAG_ACTIVITY_NEW_TASK);


    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this)
            .setContentTitle(title)
            .setAutoCancel(true)
            .setContentText(msg)
            .setDefaults(
                    Notification.DEFAULT_SOUND
                            | Notification.DEFAULT_VIBRATE);
    if(msg1 == null)
    {
        Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.app_icon);
        mBuilder.setLargeIcon(largeIcon);
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
    }
    else
    {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            //http://stackoverflow.com/questions/22119374/how-to-show-compact-notification-if-it-is-available-on-the-user-device
            try {
                Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.app_icon);

                s.bigLargeIcon(largeIcon);
                s.bigPicture(Picasso.with(context).load(msg1).get());
            } catch (IOException e) {
                e.printStackTrace();
            }
            mBuilder.setStyle(s);

        }
    }


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder
                .setSmallIcon(R.mipmap.ic_notification)
                .setColor(ContextCompat.getColor(context, R.color.bgColor));
    } else {
        mBuilder.setSmallIcon(R.drawable.ic_notification);
    }


    mBuilder.setContentIntent(pendingIntent);
    int notifID =(int)System.currentTimeMillis();
    mNotificationManager.notify(notifID, mBuilder.build());
}

【问题讨论】:

    标签: android push-notification


    【解决方案1】:

    在您的第一个else 条件中,您没有将mBuilder.setLargeIcon(largeIcon); 应用到您的s.bigLargeIcon(largeIcon); 到您的NotificationBuilder style 而不是通知生成器。

    所以只需在下面的代码中添加mBuilder.setLargeIcon(largeIcon);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    
        Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.app_icon);
    
            mBuilder
                    .setSmallIcon(R.mipmap.ic_notification)
                    .setLargeIcon(largeIcon);
                    .setColor(ContextCompat.getColor(context, R.color.bgColor));
        } else {
            mBuilder.setSmallIcon(R.drawable.ic_notification);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-21
      • 2019-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-04
      • 2014-07-19
      • 1970-01-01
      相关资源
      最近更新 更多