android - 推送通知不适用于装有 Android 6.0 MarshMallow 的三星、华硕和联想设备
问题描述
Android 推送通知在运行 Android 6.0 的三星、华硕和联想设备上无法正常工作。
- 是否需要任何许可?
- 如何处理这种异常?
- 如何一次处理至少 5 个通知?
- 如何处理每个通知的时间?
此代码没有提供正确的通知顺序,所有通知都存储在数据库中,但只会显示一个通知,其他通知不会显示,其余数据将存储在数据库中。
private void sendNotification(final String id, final String title,final String date, final String image,final String bannertype,final String product_id,final String min_discount,final String max_discount,final String brand_name,final String desc,final String sub_category_id) {
System.out.println("sendNotificationproduct_id" + product_id);
try {
// Bitmap b= getBitmapFromURL("https://cdn.pixabay.com/photo/2015/12/08/08/42/banner-1082652_960_720.jpg");
//Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.splashscreen);
int NOTIFICATION_ID = 1;
if(image.length()>0) {
Glide.
with(this).
load(WebConstants.NOTIFICATIONIMAGEURL+image).
asBitmap()
.into(new SimpleTarget<Bitmap>(100, 100) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.smlogo2)
.setContentTitle(title)
.setAutoCancel(true)
.setSound(defaultSoundUri)
// .setStyle(notiStyle)
.setPriority(Notification.PRIORITY_MAX);
NotificationCompat.BigPictureStyle bps = new NotificationCompat.BigPictureStyle().bigPicture(resource);
bps.setSummaryText(desc);
notificationBuilder.setStyle(bps);
Intent intent = new Intent(context, DashBordActivity.class);
intent.putExtra("notification",bannertype);
intent.putExtra("productid",product_id);
intent.putExtra("brand",brand_name);
intent.putExtra("min_discount",min_discount);
intent.putExtra("max_discount",max_discount);
intent.putExtra("sub_category_id",sub_category_id);
intent.putExtra("sub_category_id",sub_category_id);
//product_id,final String min_discount,final String max_discount,final String brand_name
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
});
}else
{
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.smlogo2)
.setContentTitle(title)
.setContentText(desc)
.setAutoCancel(true)
.setSound(defaultSoundUri)
// .setStyle(notiStyle)
.setPriority(Notification.PRIORITY_MAX);
System.out.println("Notiproduct_id_Notifi_Service" +product_id );
Intent intent = new Intent(context, DashBordActivity.class);
intent.putExtra("notification",bannertype);
intent.putExtra("productid",product_id);
intent.putExtra("brand",brand_name);
intent.putExtra("min_discount",min_discount);
intent.putExtra("max_discount",max_discount);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
} catch (Exception e) {
System.out.println("IO Error" + e.getMessage());
}
}
并请提供与通知相关的示例。
解决方案
推荐阅读
- sql - 尝试使用循环将多个值存储到一个变量中,并使用该特定变量进行插入
- dataweave - 如何在 dataweave 中访问 XML 中的 JSON?
- spring - 如何处理 IntelliJ 中未映射的 spring 配置文件
- javascript - 如何使用 JCF 插件更改选择框值?
- windows - 如何将 IIS 请求重定向到特定的 url
- apache-spark - spark中同一工作/阶段的任务之间的差距很大
- android - Android 10 设备上的 Resources$NotFoundException
- youtube-dl - youtube-dl mp4 或 mkv 和 720p 或更低
- python - 无法从网页中提取连接到“查看全部”按钮的链接
- haskell - 我们自己的数据类型的最大值