keeping track of online user using phone number - android

I am developing android application in which want to keep track of online users.
When the user install the app, he gives his number and country code, we register the user with that number.
Now whenever he starts the application he sends the list of all mobile contacts to server to find who is online.
The problem with this approach is same mobile number can be in different format like
+91 9665123456
91 9665123456
0 9665123456
9665123456
Lets assume while registering the user A gave number +91 9665123456 and we register the user and make it online whenever the app is running.
But in user B mobile, his number is stored as 09665123456, I need to query whether user A is online or not, but as both number are different what approach to use ?
I am not sure how whatsapp approaches to this problem?
The other way what I can think of is using libphonenumber to find the number match but it also gives probability.
Is there any other approach which is recommended to handle above scenario ?

I would suggest a below approach:
1, Your server should have a list of country codes and the corresponding number of digits allowed for a mobile number in that country
2, When the registered user A , comes online and sends his contacts to your server for the first time, you can check a contact by starting from the left end of the number. If you see a international prefix 00 or +, then take the first digit from left, identify the country code and if the remaining number of digits to the right match the defined number of digits for this country , scan the list of users registered with that country code to see a match. If no, then take the first 2 digits to see for a possible country code and check similarly.
Now if you dont see any international prefixes in a contact, that means the contact is in the same country as A and so you need to scan the list of users registered from the same country after taking the last certain number of digits as required for that country code.
3, It will be better if you generate a unique id for a each registered user which can be used as a primary key for a user database. This will eliminate the need for detailed scan for repeat users. For eg: let A have an id 123 and B have an id 456. When A logs in, set the online flag for A , then search for B and if B is already registered, then add B's id 456 to A's friends list along with corresponding number stored by A. So next time when A comes in, you will see that contact B has a unique ID assigned and so you need to go check if the online flag is set for this ID. Also this will be useful even if a user changes his/her number

I had a similar issue while developing an app. What you can do here is, to check the input for special characters, and also take the size in account. Remove the spaces, and store just the last 10 digits. This can be achieved by trimming and subString operations, if the entry type is a string. Then comparison of the two strings should result in a desired manner.

as per my suggestion
==> first of all you remove all space in your number using replace(" ","") function,
==> then use query for match last 10 character so its give you mobile number which you have want to find is there online or offline from users Contact book.

Related

How to make different authentication numbers everyday without editing code?

I am making a commuting web with vuejs and firebase.
I want to make this:
The boss gives the employee a different authentication number every day, and the employee (user) has to enter the authentication number when pressing the go to work button. (to To make sure he's the one boss hired.)
For this function, I can make this with v-if (v-if code == 123 like this), but the problem is that I cannot edit the code every day. How can I change the authentication number every day without touching the code?
I would also like to create an app that can easily change the authentication number so that the CEO can use it.
Well you can do this,
Whenever the boss sends the authentication number to a particular employee, save that authentication number in firebase under the employee's details as for eg. - "todaysAuthNo: 123456" , when the employee(user) enters the number and press the go to work button then check whether the number entered by the user matches with the number entered by the boss i.e. check whether it matches with "todaysAuthNo: 123456".
Hence, next time when the boss enters a new authentication number it will get replaced with the old number in "todaysAuthNo" and also the user will need to enter the new authentication number entered by the boss to login.

Phone number updated algorithm

I have an app where visitors register from their phone numbers (much like WhatsApp or Telegram). I store the number in e164 format.
Once he is connected, the application synchronizes his contacts with the database in order to see which contact is using the application. during synchronization the application retrieves the list of numbers from its phonebook and converts them into E.164 format before sending them to the server. so far everything is working fine.
Here is where the problem arises: recently, a country (the Ivory Coast) has decided to change its phone numbers from 8 digits to 10 digits. What's the best way to handle this?
Treat a phone number as an arbitrary value until you can verify it works. Countries change the structure of their telephone numbers all the time and in unpredictable ways.
What is valid one day may not be valid the next. What rules apply one day may not apply the next. There is absolutely no way of knowing what might happen.
Phone numbers do not really adhere to any standard at all. E.164 only establishes the calling prefix, so that's something that might follow standards, but even those can change arbitrarily as countries get created, or merge.
In other words, this is all political and there is no way of predicting the future.

how to check if a phone number is valid whatsapp number in Android?

so I have an edit text that will be used as a view to get phone number from user, say if the phone number is +6123456789 , I want to check if this number has whatsapp number or not,i want to avoid the user to input fake whatsapp number, how to do that ?
Update (Nov 2022):
Whatsapp are repurposing the contacts node starting in v2.43 to no longer provide status information about a phone number. Regardless of whether a user has WhatsApp, it will always return valid for status in the response. For more information see official docs
original answer:
You must have: Facebook Whatsapp Business Api for contacts check
Once you have a valid business account you could then query the Contact. You will get all the details in the documentation.
Hope it works for you!
You can try this service https://watverifyapi.live
It allows you to verify multiple whatsapp number at a time.

Add a specific key to a contact in android phonebook to easily identify it

I have a app which takes all the contacts from phone book and check them in my server to check if they are present or not. For which I normally take all the phone numbers each time and check for the sync.
What I want to know if there is any key which is attached to a contact item and we can change with our value so we dont have to send all numbers to server each time, we will just send those numbers which do not have value set by us. In this way we can differentiate the synced and unsynced numbers?

How do I robustly compare phone numbers in Android?

In an Android app I am developing, I have a database which maps:
<Contact ID, Contact Lookup Key> --> <My Custom Data Associated with Contact>
When an incoming SMS message comes in, I want to be able to look up My Custom Data Associated with Contact associated with the contact who sent the SMS message. I want to do the lookup in as few steps as possible.
The only data I can get out of the SMS message is the Phone Number, so the problem is basically one of mapping the Phone Number to My Custom Data Associated with Contact in as few steps as possible.
Now, I am aware that I can look up a contact from a phone number up using ContactsContract.PhoneLookup as described e.g. here. However, this does not get me to my desired result because both the Contact ID and Contact Lookup Key are subject to change. So if either the ID or the Lookup Key has changed for any contact I have persisted to my database, I have to basically load my whole database and refresh the ID/Lookup Key for each row before I can test whether they represent the same contact as the one returned by ContactsContract.PhoneLookup. This is a pretty brutal solution which I would prefer to avoid.
What I would like to do is keep a table mapping phone numbers to my custom data (in an N:1 relationship).
<Phone Number> --> <My Custom Data Associated with Contact>
This way, in theory at least, I can index the phone number column and just look up the data in one step. However, phone numbers come in many formats. My solution will only work if I can create a canonical representation of a given phone number. My plan was to use PhoneNumberUtils.getStrippedReversed to produce an efficiently indexable canonical phone number, but this fails on a trivial case, for example:
PhoneNumberUtils.getStrippedReversed("+1(306)6656320") --> 02365566031
PhoneNumberUtils.getStrippedReversed("(306)6656320") --> 0236556603
They aren't the same number!
So with that by way of long-winded explanation, my question is: Can anyone think of a way of converting a phone number to a canonical phone number so that I can perform an indexed database lookup on the number, or any other solution to the problem I described above?
You can use below method along with getStrippedReversed
public static String toCallerIDMinMatch (String phoneNumber)
*Returns the rightmost MIN_MATCH (5) characters in the network portion in reversed order This can be used to do a database lookup against the column that stores getStrippedReversed() Returns null if phoneNumber == null*
Then your comparison will give you the desired result

Categories

Resources