Android通知大图片样式和大文本样式

时间:2014-08-18 10:48:48

标签: android notifications push-notification

我使用大图片样式制作推送通知,显示为here。 是否可以混合大图片样式和大文字样式,如附图所示?我该怎么做?

enter image description here

3 个答案:

答案 0 :(得分:16)

你应该能够这样做:

Notification notif = new Notification.Builder(context)
     .setContentTitle("Title")
     .setContentText("content")
     .setSmallIcon(R.drawable.ic_small)
     .setLargeIcon(bitmap)
     .setStyle(new Notification.BigPictureStyle()
         .bigPicture(bigBitmap)
         .setBigContentTitle("big title"))
     .build();

Source

答案 1 :(得分:4)

查看更多...您的通知中的文字是子文字。 因此,在使用bigpicturestyle通知时,您需要设置

spark.yarn.executor.memoryOverhead

bigPicStyle.setSummaryText(mContent);

同时设置两者都不起作用。

答案 2 :(得分:1)

如何创建BigPictureStyle通知的示例:

 int NOTIFICATION_ID = 1;
    String ns = Context.NOTIFICATION_SERVICE;

    //Get the bitmap to show in notification bar
    Bitmap bitmap_image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

    Bitmap big_bitmap_image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);


    NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle()
            .bigPicture(big_bitmap_image)
            .setSummaryText(getResources().getString(R.string.content));

    NotificationCompat.Builder nb = new NotificationCompat.Builder(this);

            nb.setContentTitle("Notification title"))
            .setContentText("Notification Content")
            .setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(bitmap_image)
            .setTicker("Notification ticker!")
            //API Level min 16 is required
            .setStyle(style)
            .build();


    Intent notificationIntent = new Intent(this, MainActivity2.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    TaskStackBuilder TSB = TaskStackBuilder.create(this);
    TSB.addParentStack(MainActivity.class);

    TSB.addNextIntent(notificationIntent);
    PendingIntent resultPendingIntent = TSB.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    nb.setContentIntent(resultPendingIntent);
    nb.setAutoCancel(true);
    NotificationManager mNotificationManager =
            (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(NOTIFICATION_ID, nb.build());

这是完整的代码:

https://github.com/Jorgesys/Android-Notifications