Android Notification Big Picture Style and Big Text Style

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

I've build a push notification using Big Picture Style as show here. Is it possible to mix Big picture Style and Big Text Style as shown in the attached photo? How do I do it?

回答1:

You should be able to do it this way:

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



回答2:

View More... text in your norification is subtext. So while using bigpicturestyle notification you need to set

bigPicStyle.setSummaryText(mContent); 

or

mBuilder.setSubText(mSubText); 

Setting both at same time doesn't work.



回答3:

Example of how to create a BigPictureStyle Notification:

 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()); 

this is the complete code:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!