Пользовательский вид уведомлений RemoteView не отображается - PullRequest
0 голосов
/ 04 июля 2019

Я создал уведомление, используя простой макет с textview и imageview.Но после вызова NomanagerManager.notify (...);не показывает уведомление.

Ниже приведен код, который я создал

// Create notificationmanager instance
     NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            int importance = NotificationManager.IMPORTANCE_LOW;

// Setting the channelid if versioncode is greater than Oreo's
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                NotificationChannel mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, importance);
                notificationManager.createNotificationChannel(mChannel);
            }

// Creating remote views for the notifications
            RemoteViews notificationLayoutCollapsed = new RemoteViews(context.getPackageName(), R.layout.notification_layout_collapsed);
            RemoteViews notificationLayoutExpanded = new RemoteViews(context.getPackageName(), R.layout.notification_layout_expanded);

// Passing the intent 
    Intent notificationIntent = new Intent(context, HomeActivity.class);-

   // setting the flags
 notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

// Style MOST LIKELY ISSUE IS HERE
     NotificationCompat.Style style = new androidx.media.app.NotificationCompat.DecoratedMediaCustomViewStyle();

            NotificationCompat.Builder mBuilder1 = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
                    .setSmallIcon(R.drawable.ic_notification_icon)
                    .setContentTitle(context.getString(R.string.app_name))
                    .setContentText(context.getString(R.string.app_name))
                    .setContent(notificationLayoutExpanded)
                    .setCustomContentView(notificationLayoutCollapsed)
                    .setCustomBigContentView(notificationLayoutExpanded)
                    .setStyle(style)
                    .setAutoCancel(false)
                    .setContentIntent(pendingIntent);

            notificationManager.notify(NOTIFICATION_ID, mBuilder1.build());

Я также пытался использовать style = new NotificationCompat.DecoratedCustomViewStyle();

Но когда я установил стиль как BigText или BigPicture и не устанавливайте customcontentview, я вижу уведомление.

Редактировать

Я использовал оба v4.NotificationCompat, androidx.NotificationCompat Проблема в моем коде, ядумаю, что какой-то шаг отсутствует.Просьба помочь.

...