首页 > 解决方案 > 推送通知不适用于装有 Android 6.0 MarshMallow 的三星、华硕和联想设备

问题描述

Android 推送通知在运行 Android 6.0 的三星、华硕和联想设备上无法正常工作。

  1. 是否需要任何许可?
  2. 如何处理这种异常?
  3. 如何一次处理至少 5 个通知?
  4. 如何处理每个通知的时间?

此代码没有提供正确的通知顺序,所有通知都存储在数据库中,但只会显示一个通知,其他通知不会显示,其余数据将存储在数据库中。

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

}

并请提供与通知相关的示例。

标签: androidpush-notificationandroid-notificationssamsung-mobile

解决方案


推荐阅读