I am creating a college Android application where faculty choose the specific course and send them assignment notification but how i do that i don't Know... please help me..
You need to subscribe topic from Android app. Send notifications to that topic so it will received to all users who has subscribed it.
Sample code subscribe top from Android app.
FirebaseMessaging.getInstance().subscribeToTopic("news");
Send message to this topic from server-
URL- https://fcm.googleapis.com/fcm/send
Body-
{
"to": "/topics/news",
"data": {
"message": "Message to user",
"title":"title of message",
"sender":"sender name"
}
}
headers- api key from firebase
Rest you need write code from Android and Server side.
You can also send notifications form Firebase console as well.
Related
I am using Firebase for my android studio project and I want to have a notification button so that whenever a user clicks a send button, the notification button indicates there is a new notification and that notification contains the data that the user sent. Is it possible to do so using firebase ? and how ?
Sure. You want to use Topic Messaging in FCM.
Here's the setup guide.
Once implemented, subscribe a user with:
FirebaseMessaging.getInstance().subscribeToTopic("dogs")
And send a notification via a POST request on the app (insecure, not recommended) or via a server (recommended):
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
"message":{
"condition": "'dogs' in topics || 'cats' in topics",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message",
}
}
}
I don't know, whether you figured it out or not (because you asked the question months ago), but I may have an idea. Actually I was also searching for what you asked to do, and I read your question. I wanted to do the same thing as you. Then I thought, if firebase cloud messaging service can receive http POST request not just from firebase console but also from any other service like ARC (Advanced REST client).
So the solution :
Send a JSON HTTP post from your app when the users click on the app with the required data received from user. Now when the JSON response is received by the firebase cloud messaging server, it should you the notification to every user with the data sent by the user who clicked the button.
I haven't tried it yet but I am going to try it now. I will let you know in the comments if it works or not. It should work theoretically. If you have already figured out a way to send such notifications, please don't forget to share your method.
If you want to know how to send JSON HTTP post, then here is a stack overflow answer : SENDING JSON OBJECT
I'm creating a basic Guest Service Request system with the use of Yii2 which has a function of when there's a new request that was inputted to the system the employee phone will be notified.
How do I create a firebase notification in Android, I don't really have any ideas but I do have some basic knowledge when it comes to Android developing.
Some basic steps:
Add the Firebase SDK in your Android application.
Get the authorization key.
Get the registration token for the client app instance.
Send the registration token to the server.
Send HTTP request in Yii anytime you want to send the notification:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=Your_Authorization_Key
{
"registration_ids": ["registration_token"],
"data": {
"message": "This is a Firebase Message!",
}
}
Receive notification in Android app.
I figured how to send and receive Firebase Push notifications using Firebase Cloud Messaging
I want to know how to send a notification manually using code in android studio so I can send it from any phone.
You send messages from your phone using FCM. You need to make a POST to https://fcm.googleapis.com/fcm/send api with payload that you want to send, and you server key found in Firebase Console project.
As an exameple of payload sending to a single user with to param:
{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
Also, to param can be used for topics "to": "topics/yourTopic"
In data you can send whatever you want, message is received in onMessageReceived() service from Firebase.
More details you can found in Firebase documentation.
I tried a sample code to test the push notification system with Firebase and it's working well except one thing.
If I try to send a notification from Firebase console, using Device Token, the notification shows in device.
If I try to send a notification from Firebase console, using my topic topik, all notifications show in all devices.
If I try to send a notification from my web page or from postman, using Device Token, the notification shows in device.
If I try to send a notification from my web page or from postman, using my topic topik, NOTHING HAPPENS.
This is a example call:
link: https://fcm.googleapis.com/fcm/send
POST method
Header field:
Content-Type : application/json
Authorization : key=MY_SERVER_KEY (the new one)
Body:
{
"to": "/topics/topik",
"data": {
"title": "This is a Firebase Cloud Messaging Topic Message!",
"content-text": "This is a Firebase Cloud Messaging Topic Message!"
}
}
or
Body:
{
"to": "/topics/topik",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!"
}
}
the result on send action is something like this
{
"message_id": 7150560334538835864 (SUCCESS!)
}
but no notification arrives in any device. I tried to debug the onReceive method, but nothing happens.
Any idea?
Are you trying to send data-messages or notification-messages?
see: https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
If you want to send notification-messages (the type of messages sent by the notification console)
the payload you wrote in the question is wrong. Try replacing data with notification:
Body:
{
"to": "/topics/topik",
"notification": {
"title": "Hello",
"body": "This is a Firebase Cloud Messaging Topic Message!"
}
}
let me explain my requirement, I want to send a notification to my users on their(Android) when any changes happen on table.
Using SAP NW Gateway I could able to send notification to any listener(listener class)when my table record updated/deleted.
Now I want to send this notification to users android devices,I have seen GCM but not able to understand how can I post my notification received to GCM and send that message from GCM to Android devices.
Please let me know if I can post my notification details to GCM how to send(read the sent message over GCM) to devices.
Notifications(using SAP Gateway) I am receiving is in XML format.
Thanks
Rajesh
To send a message, the application server issues a POST request to https://android.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA
{
"registration_ids" : ["APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."],
"data" : {
...
},
}
Contents of data lands on connected GCM clients. Of course, you must first configure GCM API in your google developer's console.
https://developer.android.com/google/gcm/server.html
https://developer.android.com/google/gcm/http.html