Уведомления Android Oreo отображаются в строке состояния, но не в точечных уведомлениях - PullRequest
0 голосов
/ 30 ноября 2018

Я создал пользовательские уведомления, используя удаленные представления.Они работают в обычных уведомлениях, но не отображаются в точечных уведомлениях.Я приложил фрагмент кода, который использовал для создания уведомлений.

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.widget.RemoteViews;

import com.nataraj.android.justweather.MainActivity;
import com.nataraj.android.justweather.R;

public final class NotificationUtil {

    static final String NOTIFICATION_3H_CHANNEL_ID = "com.nataraj.android.justweather.3_hour_notification";
    private static final int NOTIFICATION_3H_ID = 1;

    private static NotificationCompat.Builder getNotificationBuilder(Context context, String city, String temp, int weatherIcon) {

        RemoteViews notificationLayout = new RemoteViews(context.getPackageName(), R.layout.notification_small_layout);
        RemoteViews notificationBigLayout = new RemoteViews(context.getPackageName(), R.layout.notification_large_layout);

        notificationLayout.setTextViewText(R.id.notification_city_name, city);
        notificationBigLayout.setTextViewText(R.id.notification_city_name, city);
        notificationLayout.setTextViewText(R.id.notification_temp_view, temp);
        notificationBigLayout.setTextViewText(R.id.notification_temp_view, temp);
        notificationLayout.setImageViewResource(R.id.notification_weather_icon, weatherIcon);
        notificationBigLayout.setImageViewResource(R.id.notification_weather_icon, weatherIcon);

        return new NotificationCompat.Builder(context, NOTIFICATION_3H_CHANNEL_ID)
                .setSmallIcon(R.drawable.ic_launcher_foreground)
                .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                .setCustomContentView(notificationLayout)
                .setCustomBigContentView(notificationBigLayout)
                .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                .setContentIntent(getIntent(context))
                .setAutoCancel(true);
    }

    private static PendingIntent getIntent(Context context) {
        Intent pendingIntent = new Intent(context, MainActivity.class);
        pendingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        return PendingIntent.getActivity(context, 0, pendingIntent, 0);
    }

    public static void showNotification(Context context, String city, String temp, int weatherIcon) {
        NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context);
        notificationManagerCompat.notify(NOTIFICATION_3H_ID, getNotificationBuilder(context, city, temp, weatherIcon).build());
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...