How to authenticate friends by phone number in Android (Kotlin)? - android

I want make app to have friends concept between certain users.
For example, person A and person B are friends offline.
Person A is registered in App, and if he submit person B's phone number and sends link of this app to person B, person B can register this app with certain authentication number.
So when person B is registered, with this authentication number, app can save data in DB as person A and person B are friends.
This process needs way to send link to user having authentication.
Is there way to implement this in Android (especially Kotlin)?
Or other ways are also fine if it can also authenticate they are frieds.
Please help me.

Related

Android send shopping card order e-mail with attachments without using intent

I've developed an Android app with a self developed shopping cart. At the end of the purchase process I want to send an automatic email to the store owner in order to proceed with order.
Till now I used an email intent in order to force the user to send an email by themselves but the store owner got too many complaints from the users. So now I'm searching for another solution in order to do it in the background.
I've searched around but didn't find a proper solution. The email should contain a bit of text information along with 1-n attachments from users phone.
Do you have any suggestions?
Proper solution would be to send it through web service. But if you want to do it through email in background of your app you must provide possibillity to sign in to email address and send it, it would be like creating another email client.
Think about creating web service to which you will send these orders it is way better solution than sending emails from background of your app.

When to register an FCM token for a user

I have some doubts about implementing Firebase Cloud Messaging in my app.
My app is a chat similar to whatsapp and facebook messenger. Right now every time someone logs in I register the token and relate it to the user. So if someone wants to chat to an user the app searches the Db for the user ID and there I have his token.
I'm able to register the device token but I'm not sure when should I do that.
In my chat users register through a mail/password signup and is possible that an user could login in other device.
For example:
User Frehley uses a Galaxy 8 and is able to chat and receive notifications in his device using the token. But lets say that he loges in another device. I need to register the token again and relate it to him right?
So, maybe I'm wrong but the best moment to register the token is every time the user logs in and replace it in the DB. Right?
Now, lets say two users (Frehley and Stanley) uses the same Galaxy 8 to login, the token will be diferent everytime the login or it is the same for every single device?
This all depends on the use-case:
If the same user is logged in to two devices, do you want them to receive the notification on both devices? If so, you'll need to store multiple device tokens per user and send the notification to each token for the targeted user. You could also use a device group to identify the devices for a single user. From those docs:
With device group messaging, you can send a single message to multiple instances of an app running on devices belonging to a group. Typically, "group" refers a set of different devices that belong to a single user
If you want the user to only receive the notification on the device that they were last using, you'll have to associate a single token with each user and overwrite that when they start the app on a device. Not that this is not necessarily when they log in, but more likely when the app detects that they're authenticated.
If a different user uses the same app on the same device (using the same device profile), you probably want to stop sending to the device token. The most robust way to do this is to remove the association between the previous user and the token, but that may require that you keep a mapping from token to UID. An easier way is to delete the device token when a user signs out. Then the new user signs in, they will then get a new token.

Firebase Cloud Messaging device id: multiple user in same app in same device

Is there a way to create a registration id with scope of logged in user. I have an app which allows user to login as different user (say one user as student and other as a parent). User can switch between the users. Case is somewhat similar to gmail app where multiple email ids can be logged in at same time.
The issue is when we call
FirebaseInstanceId.getInstance().getToken()
It will give the device id for that app instance. So if i am to target a specific user logged in i cannot.
One way i can accomplish targeting a user is to send user_id explicitly as data, which in my case is not efficient as it will take to send one FCM send request for each user. Is there anyway this can be accomplished. Would like to know how gmail is handling user specific notifications.
Token (reg id) is intended to represent a mobile device.
As you've said you can send in payload or in tags which user the push notification is destined to, check if it is the same as the current logged in user and decide whether to create the notification or not.
The only problem here may be, how to identify the current user if at the moment of push arrival your application is killed or all users are logged out. I think in this case the solution depends on privacy level of the pushed data.

Google Cloud Messaging - Multiple Account Multiple Device

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..

Using GCM for device to device app data sync

I am planning to build a shopping list application, wherein grocery items from one user (tied to one google account on the smartphone) can be sent over to another app user (tied to another google account on his/her smartphone).
Seeing GCM, I am not sure, if we can do a device to device kind of data sync? Any ideas on how this sort of stuff is basically implemented in a quick and easy way would be highly appreciated.
you dont necessarily need to use GCM or any messaging service, all gcm is meant to do is notify a device that something has changed on your server and that you need to go get all the new stuff.
that being said all you need to do is just have a sync button that the user can manually sync the list from the server to the device and vice versa which would get rid of the need for GCM.
if you wanted automatic syncing then GCM or any other messaging service would be what you want
To elaborate on tyczj's answer, you will need a server anyway to store GCM registration ids from your users. So you can use the same server to host groceries items for them.
So the flow will be like this:
User A wish to send groceries list to User B, he uploads groceries list via your server's Web Service API, along with User B's google email address.
Your server has a list of GCM registration ids, which will be associated with their google email address. The server finds the GCM regid of user B, and push a notification with a URL to download the groceries list to him.
User B's phone receives GCM message, display a notification to let the user download the groceries list from the URL in the GCM message.
GCM is only needed if you want this 'real-time' way of syncing the list. You could also omit GCM, in which case, User B will only know User A has shared the list with him, when he runs the app (i.e. every time app is run, it will perform 'is there someone sharing a list with me' command).

Categories

Resources