I am trying to create a android messaging app using MQTT.
But i just want to know how the existing messaging apps(based on MQTT) work?
I am think of creating a unique topic for each user who installs and setups the app for the first time (providing his mobile no/email id for his topic to receive messages from others).
Once the setup is completed the contacts from users device will be synced with my server to check the available users.
And finally the user can select from the available contacts to send messages(publish messages based on the selected contacts mobile no or email id).
I know we should encrypt the contacts to protect the users privacy but,
Am i going in the right direction?
Thanks in advance.
Typically you set up a topic like
appName/device/[deviceID]
you could then put additional topics under that, like
appName/device/[deviceId]/contacts/contactName
You would then create authorization rules that limit a device to only publish things to appName/device/[deviceId]/# for the specific device id.
You could do a topic like appName/device/[deviceI]/contacts/online to get a list of available contacts... and a reply topic that gave back the results.
Related
I am designing an application which has two types of user, vendor and Customer. Vendor delivers product and customers order them.
I want to send a notification when a Customer orders something from a vendor. Only that vendor should get notification. Similarly, when the product is mark delivered by vendor, a notification should appear on the customer side.
I was thinking of storing tokens in Firebase Database in the profile for each user, so let's say a customer orders something, he can retrieve Vendor's token so a notification appears on Vendor's side.
I recently came across this answer Cannot resolve symbol com.google.firebase.messaging.Message
which says it's not possible to do so, without admin SDK, which can't be used in Android App.
What options do I have for this use case?
Do I have to create my own server? Is there anyway to do this with just Firebase?
I fell into this same problem before and I solved it by using a token which is the same as in my national number application through the topicKey when the employee sends to the user or I already created the topicKey for the user when he is in the process of registering in the application which is the national number.
When the employee accepts the user’s request, add the order number to the topicKey, which is the national number.
In your problem you can use the phone number because it is a unique code and create a topicKey based on it.
I hope I understood your problem correctly and I apologize for the spelling errors because it is not my native language.
I am trying to develop the Messenger App like Whatsapp using Firebase.
I'm already done the code for device to device notifications and now I am trying to send the notifications to specified group.
Please provide the example code for the Group Notifications.
There are a few ways to send messages to groups of users:
Send the message to a topic that all users subscribe to. This is the simplest scenario, since you don't need to keep a list of tokens. But you have less control over the actual people that receive the message, as anyone who knows a topic can subscribe to it.
Keep a list of device tokens for each group in your app server, and then send to each individual device in the group.
You can also use the previous version of the API to send to batches of up to 500 tokens at a time. This sort of multicast delivery is not yet possible in the new API.
For an example of this, see the documentation of Cloud Functions and the sample repo.
Send to a device group with the legacy API. I'd only recommend this approach if the devices are actually owned by one user, which is the case that device groups are meant for.
Try this link
Don't forget this line Authentication:
key=<Your_API_Key>
The word (key) is important
I've been looking into implementing firebase for my mobile applications. I understand how to set it up on the applications. Followed some tutorials
https://www.sitepoint.com/creating-a-cloud-backend-for-your-android-app-using-firebase
https://www.androidhive.info/2016/06/android-getting-started-firebase-simple-login-registration-auth/
My questions are:
Can I authenticate my users by only username or uuid no password required?
How can I set up the database to get data from my current server.
Can I push different notifications to each user and have the option to send to a group or all users?
Thanks in advance
Yes you can achieve this using Firebase Anonymous Authentication for Android and for iOs. IMHO, is my actual favorite because you can actually log in a user without getting any information from them, no email, no password and no OAuth authorization necessary. You need just to click a button an log in.
An important thing to remember is that when the user decides to become a real user, you can merge those two accounts into a real account.
You can easily get data from your server accordingly to your operation system, Android or iOs.
For push notification i recomand you using Firebase Cloud Messaging. Is a cross-platform messaging solution that lets you reliably deliver messages at no cost.
Hope it helps.
I want to build an Android app that allows a user to send notification and data messages to other users. I've started using Firebase only recently, and Firebase Cloud Messaging is still pretty confusing to me.
I have already implemented sending a message to a specific device using the Firebase Instance Id. However, in my app, a user can log out and log into their accounts using different devices, so this isn't really what I want. I read the documentation and it's pretty confusing, they mention sending messages to user groups, and topics (which only apps can subscribe to, not users).
Is there a way to send a push notification directly to another user or a group of users using only their UIDs? If not, is there any other way I can implement this?
I did it storing the FCM Token in a device structure by user. When the user login, add the deviceData to the userToken structure. You need clear deviceData when the user logout. This way, you will only send notifications to logged devices.
Ex (This is not like mine structure, but it can help you to wondering a good way to do this):
-userToken
-idUser1
-device
-idDevice1
-fcmToken: "xxxxx"
-idDevice2
-fcmToken: "YYYYY"
Hope that I helped you
Alright, so to make sure this works across multiple devices when a user logs in, I just make the device subscribe to a topic with the name equal to the user's UID. Now if I want to send a notification to a user, I just send an FCM message on the topic with the name equal to the user's UID!
Example: If my UID is equal to "asdf", whenever I login using multiple devices, each of the devices automatically subscribes to the topic with name "asdf". So now, if I send an FCM from the server on this topic, all the devices from which I am logged on to obtain this notification.
I am learning how to implement the GCM both from client side (Android) and from server side (ASP.NET). I spent a bit of time on reading the whole google documentation related to GCM and I also tried the sample that they provided.
Because I need to integrate the GCM in an already existing app, I would like to know some specific stuff.
As I got it, the registration id is a token which ties the app on a specific device to the GCM service and the app server; so, the backend can send downstream messages directly to that device.
In my scenario, I could have multiple users who can use the app on the same device, that means they need to login in the app and they have an account on a database in the server side. Do I need to store a different registration id for each user on that device? Or still the registration id refers to only the app?
And what about the same scenario but distributed on multiple device, because a user can have multiple devices?
Thanks in advance.
This relates a lot to the context of your app and what you want to do with notifications
Having one registration ID per device will be okay.
I manage my multiple users by using subscription tags handled by my server.
So take the scenario if you have a sports app:
User A & User B share the same device. Each user subscribes to a tag.
User A is subscribed to two tags (Basketball & Football)
User B is subscribed to two tags (Tennis & Basketball)
When User A logs out you clear the tags associated with that user and when User B logs in you fetch his/her tags.
Your server knows notifications to send to the device based on the tags the user has subscribed for.
Multiple device scenario:
The same goes, when your user logs In you get their tags. The device also has its own token from GCM.
The registration id is the app's id, it may be changed if app version was updated. Your push notification will be sent on device with your app, regardless user account. So every user on every device will receive your notification, you must store only one refistration id per device.
For multiple users: If your messages are user specific, you would want to retrieve the user's token and subscribe to it only while they are logged in. When you switch users remove/unregister the previous token, then save/register the new user's token.
You should not only do this if you have multiple users per device, but when a user signs out. This will prevent user-specific messages being shown at wrong times to wrong users.
For multiple devices: it sounds like you are looking for Device Group Messaging.
With device group messaging, app servers can send a single message to multiple instance of an app running on devices belonging to a group. Typically, "group" refers a set of different devices that belong to a single user.
This is also nice because of the collapse_key. When one of the devices on the same account opens a notification, it will dismiss the notification on the other devices..