如何发送更大的推送通知?
Posted
技术标签:
【中文标题】如何发送更大的推送通知?【英文标题】:How to send bigger push notifications? 【发布时间】:2018-02-07 08:10:38 【问题描述】:我刚刚收到来自 Slotomania 的推送通知,它比其他人要大得多。它还具有自定义背景颜色。
有人知道如何使用这些大型推送通知吗?
【问题讨论】:
你之前尝试过什么? 这不是一个“为我做一个项目”的网站。展示你的代码实现并询问任何错误。 【参考方案1】: ***big push notifications***
private void sendNotification(String path, String fileName)
Context context = getBaseContext();
Intent notificationIntent = new Intent(this, yourActivity.class);
notificationIntent.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_NEW_TASK);
notificationIntent.putExtra(Constant.PATH_INTENT_KEY, path);
notificationIntent.putExtra(Constant.FILENAME_INTENT_KEY, fileName);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /*Request code */, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.BigPictureStyle bigImage = new NotificationCompat.BigPictureStyle();
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = null;
int notificationId = (int) System.currentTimeMillis();
notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.icon)
.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
.setContentTitle(tittle)
.setContentText(fileName)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setPriority(Notification.PRIORITY_DEFAULT)
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.FLAG_NO_CLEAR);
File imgFile = new File(path);
if (imgFile.exists())
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(imgFile.getAbsolutePath(), MediaStore.Images.Thumbnails.MINI_KIND);
notificationBuilder.setStyle(bigImage.bigPicture(bitmap));
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, notificationBuilder.build());
【讨论】:
以上是关于如何发送更大的推送通知?的主要内容,如果未能解决你的问题,请参考以下文章