Associating phones by phone numbers in Android, application architecture question
I am building this app that will develop relationships between the users on the contact list of a phone. I am at the point now where once a user installs this app he/she will be able to send a message to one or more people from the contact list. If a person from the contact list doesn't have my app installed he/she would get a pure text message with a link to view the message, download the app so the messages start coming into the app as opposed to by sms, simple. If they do have it installed i need the sender to be aware of it and push a C2DM notification about a new message. I have all of the app functionality built, the only thing that's left is this relationship piece...
I could do this by knowing if a user with this phone number is running my app, then cross reference the number with someone elses contact list... but i need to deal with international numbers, users having or not having "1" in fron开发者_运维问答t of their numbers (in US), then we have a different form of numbers in Europe and elsewhere... problems grow. For example, i am in US and if i have a friend on my contact list in Europe, his number on my phone would include some country codes, where the number stored on his phone would not. I am running into a problem of verifying users identity. If i go by phone number which guarantees the uniqueness there could be an issue of spoofing it. I could verify the phone number by sending text message from the app to my server, is it safe enough?
Bottom line is: i need the app to be aware that one of my contacts have the same app installed without sending invites, acceptance and else. Maybe i am over-thinking this, or maybe there is no way to do this...
Your thoughts and recommendations are very welcomed and appreciated.
Thanks and enjoy your weekend :)
Statistics and heuristics to the rescue:
Caller ID on many phones (or all of them? - I'm not sure) is based on the last 6 or 7 digits of the number. While this isn't universally unique as the fully qualified number (including international and area codes), it has a extremely high probability of being unique enough for a specific person's contacts. It's a classic case where in theory you could be wrong, but in practice you almost never are. The number of errors in practice is so vanishingly small that you aren't even aware of the fact that they could happen...
I think that you can use the same heuristic and safely assume that during the early life of your application the chance of two people in your database having the same last 7 digits in their phone number is small enough not to matter.
You can easily monitor your database for collisions - people with the same last 7 digits, by querying periodically (I'd do it manually - say once a week, not point in automating this right now). The idea is to find out when your user base has finally grown enough for such collisions to arise. You only want to spend time on dealing with the problem when it's left the realm of theory...
Once you get to this stage you can add further heuristics based on user geography - for most of the people, most of their contacts are in the same country and the same area code, so when in doubt based your decision on the original user's locality based on their own phone number. While not full proof, it most likely works in the majority of cases.
Another heuristic you could use is based on the social graph - my contacts are likely to be connected between themselves. So if a number in my contact list could belong to two different individuals in your database, check whether other people in my contact list that are already your users have that same number in their contact list as well and prefer the individual that is more closely connected to me.
Finally, for the few cases where you're not sure, you can just either err on the side of safety (i.e. ignore that number) or maybe have your application ask the user. On a per-user basis, this is likely to happen on very few occasions so it's unlikely to get your users mad at you for bugging them.
Normalize the phone numbers to be valid internationally.
In GSM, international phone numbers start with a "+", followed by the country code.
If you find a number without a "+", use information about the persons home country to transform the number.
精彩评论