如何在 setStyle Notification 中同时使用 BigTextStyle 和 BigPictureStyle? [英] How to use both BigTextStyle and BigPictureStyle in setStyle Notification?

查看:14
本文介绍了如何在 setStyle Notification 中同时使用 BigTextStyle 和 BigPictureStyle?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的通知中同时使用 BigTextStyle 和 BigPictureStyle.但是 setStyle 只接受一种样式.

I am trying to use both BigTextStyle and BigPictureStyle in my notification.But setStyle accepts only one style.

我的代码:

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
mBuilder.setVisibility(1);
mBuilder.setSmallIcon(R.drawable.app_icon1);
mBuilder.setContentTitle(title.toString());
bigTextStyle.bigText(description.toString());
//mBuilder.setSubText(bigText.toString());
if (bigImage != null && !bigImage.toString().equals("")) {
    mBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(ImageUtil.getBitmapFromUrl(bigImage.toString())));
}
mBuilder.setStyle(bigTextStyle);
mBuilder.setPriority(Notification.PRIORITY_MAX);
mBuilder.setContentIntent(contentIntent);

我怎样才能同时使用两者?.我想与图像一起显示文本(带换行符)!

How can i use both ?. I want to show text(with line breaks) along with the image!

推荐答案

抱歉回复晚了..其实我也遇到了同样的问题并得到了解决方案,所以我认为它可以帮助其他用户.

由于我们不能同时使用 NotificationCompat.BuilderBigTextStyleBigPictureStyle 方法,所以我们可以创建 CustomView.

Sorry for late reply..Actually i was also faced the same problem and got the solution, so i am thinking that it can help for other user.

As we can NOT use the both BigTextStyle and BigPictureStyle method of the NotificationCompat.Builder than we can create the CustomView.

我们可以使用NotificationCompat.BuildersetCustomBigContentView(RemoteViews)方法,创建我们自己的视图来显示带有大文本的大图像.

We can use the setCustomBigContentView(RemoteViews) method of NotificationCompat.Builder and create our own view to show the Big Image with Big text.

请检查以下代码:-

PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), i,
                PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);


        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
        notificationBuilder.setContentTitle("YOUR_APP_NAME");
        notificationBuilder.setContentText(body);
        notificationBuilder.setTicker("YOUR_APP_NAME");
        notificationBuilder.setAutoCancel(true);
        notificationBuilder.setSound(defaultSoundUri);
        notificationBuilder.setCustomBigContentView(remoteView("YOUR_MESSAGE_TO_SHOW"));///IT IS THE MAIN METHOD WHICH WE USE TO INFLATE OR CREATE THE CUSTOM VIEW
        notificationBuilder.setSmallIcon(getNotificationIcon(notificationBuilder));
        notificationBuilder.setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify((int) System.currentTimeMillis(), notificationBuilder.build());

下面是我们从 setCustomBigContentView() 方法调用的 RemoteViews

Below is the RemoteViews which we have called from our setCustomBigContentView() method

 private RemoteViews remoteView(String message)
    {
        RemoteViews views;
        views = new RemoteViews(getPackageName(), R.layout.YOUR_LAYOUT_HERE);
        views.setImageViewBitmap(R.id.YOUR_BIG_IMAGE_ID_FROM_LAYOUT, bitmap);
        views.setImageViewBitmap(R.id.YOUR_APP_ID_FROM_LAYOUT, BitmapFactory.decodeResource(getResources(), R.drawable.APP_ICON_OF_YOUR_APP));
        views.setTextViewText(R.id.YOUR_BIG_TEXTVIEW_ID_FROM_LAYOUT, message);
        return views;
    }

我已经创建了类似的自定义通知

I have created the custom notification like it

这篇关于如何在 setStyle Notification 中同时使用 BigTextStyle 和 BigPictureStyle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆