如何为android oreo使用firebase通知

如何为android oreo使用firebase通知,android,Android,} 这是我的密码。 通过使用此代码,所有手机都会显示通知, 但奥利奥手机中没有。 我还更新了我的firbase依赖项。 但仍然不起作用 我也使用了频道,但我不知道如何在firebase中使用它。 有人能帮我在基于oreo的手机上获取通知吗。自从安卓O以来,谷歌增加了NotificationChannel 演示如何使用通道按主题对通知进行分类。这项功能是在Android O中添加的,允许用户对其通知首选项进行细粒度控制 使用此方法返回NotificationCompat.Builder 请务必使用

}

这是我的密码。 通过使用此代码,所有手机都会显示通知, 但奥利奥手机中没有。 我还更新了我的firbase依赖项。 但仍然不起作用

我也使用了频道,但我不知道如何在firebase中使用它。
有人能帮我在基于oreo的手机上获取通知吗。

自从安卓O以来,谷歌增加了NotificationChannel

演示如何使用通道按主题对通知进行分类。这项功能是在Android O中添加的,允许用户对其通知首选项进行细粒度控制

使用此方法返回NotificationCompat.Builder


请务必使用最新的支持库。

我投票将此问题作为离题题结束,因为一遍又一遍地重复同一句话既没有帮助也没有建设性。描述问题并提出问题。
    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());
    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    Log.e(TAG, "From: " + remoteMessage.getFrom());

    if (remoteMessage == null)
        return;

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.e(TAG, "ProfileResp Payload: " + remoteMessage.getData().toString());

        try {
            JSONObject data = new JSONObject(remoteMessage.getData());

            String title = data.getString("title");
            String message = data.getString("message");
            //imageUri will contain URL of the image to be displayed with Notification
            String imageUri = remoteMessage.getData().get("trailer_img");
            //To get a Bitmap image from the URL received
            bitmap = getBitmapfromUrl(RestURLs.BASE_URL+imageUri);
            sendNotification(title, message, bitmap);
        } catch (Exception e) {
            Log.e(TAG, "Exception: " + e.getMessage());
        }
    }
}

/*
 *To get a Bitmap image from the URL received
 * */
public Bitmap getBitmapfromUrl(String imageUrl) {
    try {
        URL url = new URL(imageUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap bitmap = BitmapFactory.decodeStream(input);
        return bitmap;

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;

    }
}
// [END receive_message]

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 */
private void sendNotification(String ttl, String messageBody, Bitmap image) {
    Intent intent = new Intent(this, ActivityHome.class);
    intent.putExtra("title", ttl);
    intent.putExtra("message", messageBody);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(ttl)
            .setContentText(messageBody)
            .setStyle(new NotificationCompat.BigPictureStyle()
                    .bigPicture(image))/*Notification with Image*/
            .setAutoCancel(true)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
public NotificationCompat.Builder initChannels(Context context) {
    if (Build.VERSION.SDK_INT < 26) {
        return new NotificationCompat.Builder(context);
    }
    NotificationManager notificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationChannel channel = new NotificationChannel("default",
            "Channel name",
            NotificationManager.IMPORTANCE_DEFAULT);
    channel.setDescription("Channel description");
    notificationManager.createNotificationChannel(channel);
    return new NotificationCompat.Builder(context, "default");
}