Android - 大图片样式图像无法正常显示

时间:2016-10-18 06:28:17

标签: android image android-notifications

大图片风格的图像没有以正确的方式显示。它从顶部和底部切割。

以下是生成通知的代码:

private void notificationWithImage(String url, String msg, int smallLogo) {
    try {
        Bitmap icon1 = BitmapFactory.decodeResource(getResources(),
                R.drawable.ic_launcher);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setAutoCancel(true)
                .setContentTitle("XXXXXXXAPP")
                .setSmallIcon(smallLogo)
                .setLargeIcon(icon1);

        NotificationCompat.BigPictureStyle bigPicStyle = new NotificationCompat.BigPictureStyle();
        // bigPicStyle.bigPicture(Picasso.with(getApplicationContext()).load(url).resize(320, 256).centerInside().get());
        Bitmap bitmap_image = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_edited_noti);
        bigPicStyle.bigPicture(bitmap_image);
        bigPicStyle.setBigContentTitle("XXXXXXXAPP");
        bigPicStyle.setSummaryText(msg);
        mBuilder.setStyle(bigPicStyle);

        if (getLoginDetailFromPrefs())
            resultIntent = new Intent(this, Perspective.class);
        else
            resultIntent = new Intent(this, LoginActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        if (getLoginDetailFromPrefs())
            stackBuilder.addParentStack(Perspective.class);
        else
            stackBuilder.addParentStack(LoginActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager = (NotificationManager)
                getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(1, mBuilder.build());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

我添加了问题的屏幕截图 enter image description here

1 个答案:

答案 0 :(得分:0)

你想要的东西可以通过使用RemoteView in Notification& amp;然后在Builder中应用customView。

这是使用RemoteViews的模板代码: -

 RemoteViews remoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_layout);

 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())

                        .setSmallIcon(R.drawable.notification_small)
                        .setColor(getApplicationContext().getResources().
                         getColor(R.color.colorPrimary))
                        .setCustomBigContentView(remoteViews)
                        .setLargeIcon(bitmap)
                        .setContent(remoteViews)    
                        .setOngoing(true)
                        .setContentTitle("")
                        .setAutoCancel(false)
                        .setTicker(getString(R.string.app_name), remoteViews)
                        .setPriority(Notification.PRIORITY_HIGH)
                        .setContentText("");

      NotificationManager mNotificationManager =(NotificationManager) 
     getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
      mNotificationManager.notify(1, mBuilder.build());