How To Create Topic in FCM Notifications

AndroidFirebaseGoogle Cloud-MessagingFirebase Notifications

Android Problem Overview


I'm trying Firebase-Notification API the service is worked perfect when i send downstream message from console to app, but how to send message to topic registered users ?

i did in android side

FirebaseMessaging.getInstance().subscribeToTopic("TopicName");

but when i try send downstream message from console to topic it's says

This project does not have any topics

EDIT : i figured out that after mapping the topic it's take up to 1 day to show up in Firebase Console

Android Solutions


Solution 1 - Android

This is an alternate path.

If you subscribe a client app to an unexisting topic then the topic will also be created without having to call any firebase url request.

It' will also take a couple of hours to appear on Firebase Console.

By using google shared example: https://github.com/firebase/quickstart-android/tree/master/messaging you can confirm the same.

        FirebaseMessaging.getInstance().subscribeToTopic("news");
        Log.d(TAG, "Subscribed to news topic");

Solution 2 - Android

First, given that IID_TOKEN is your registration token and TOPIC_NAME is the topic you want to create, you need to create topic by making a POST request to

https://iid.googleapis.com/iid/v1/IID_TOKEN/rel/topics/TOPIC_NAME

And to check your created Topics make a GET request on this URL

 https://iid.googleapis.com/iid/info/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA?details=true

and insert your API_KEY in your Request HEADERS

Authorization: key=YOUR_API_KEY

Your topic will take up to 1 day to show up in Firebase console so for testing you can make curl request or use sofware like Advanced REST client

Solution 3 - Android

Firebase takes time to create new topic in console. In my case, new topic was created after 4 hours.

Solution 4 - Android

You can create a topic with http api:

https://iid.googleapis.com/iid/v1/IID_TOKEN/rel/topics/TOPIC_NAME

1. IID_TOKEN = Device registration token, you can find it with following command on your android device :

String IID_TOKEN = FirebaseInstanceId.getInstance().getToken();

2.TOPIC_NAME = new a topic name

3.Authorization: key=YOUR_API_KEY. Set this parameter in the header. Look to screenshot: Creating new topic via Advanced rest client

YOUR_API_KEY: console.firebase.google.com

and send request and you will be receive http status "OK".

Then you can get infos about all your topics in your current project with following api :

https://iid.googleapis.com/iid/info/IID_TOKEN?details=true

here need add Authorization key to header of request and you will be receive your topics list: response info topics

I recommend read this article about Instance ID/Server by Google

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMoh'd AwadView Question on Stackoverflow
Solution 1 - AndroidJuan PabloView Answer on Stackoverflow
Solution 2 - AndroidMoh'd AwadView Answer on Stackoverflow
Solution 3 - AndroidAbhishekView Answer on Stackoverflow
Solution 4 - AndroidSBotirovView Answer on Stackoverflow