Не удается разрешить метод "builder ()" - PullRequest
0 голосов
/ 09 февраля 2020

Я хочу отправлять уведомления темам с FCM без использования консоли Firebase. Когда я создаю новое сообщение с помощью Документация Firebase , это проблема.

Изображение проблемы

Вот мои коды:

 public void sendToTopic() {

        Message message = Message.builder()
                .putData("score", "850")
                .putData("time", "2:45")
                .setTopic("1")
                .build();


    }

public class MyFirebaseMessagingService extends FirebaseMessagingService {


    private static final String TAG = "MyFirebaseMsgService";
    public void onMessageReceived(RemoteMessage remoteMessage) {

    }


    private void sendNotification(String messageBody) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        String channelId = ("asda");
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                        .setSmallIcon(R.drawable.book_icon)
                        .setContentTitle("Test")
                        .setContentText(messageBody)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(pendingIntent);

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

        // Since android Oreo notification channel is needed.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId,
                    "Channel human readable title",
                    NotificationManager.IMPORTANCE_DEFAULT);
            notificationManager.createNotificationChannel(channel);
        }

        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
    }

}

1 Ответ

1 голос
/ 09 февраля 2020

Класс Message находится внутри Firebase admin sdk, но вы не можете использовать это в своем проекте android, вы можете использовать только firebase admin sdk на стороне сервера, и там вы сможете используйте класс Message. Проверьте документы для справки: -

https://firebase.google.com/docs/cloud-messaging/manage-topics

...