I have edit text element that will get the phone number, I need the phone number to be include country code in +xxx format. I am using android:inputType="phone"
how I can force the input to have that +Countrycode in the number?
I want something like Google contacts if possible or similar. If instead of flag just the country code is possible , that is also OK.
Finally I used IntlPhoneInput. Although I had to tweak it for my usage but this is a nice library.
Its available on gradle.
compile 'net.rimoto:intlphoneinput:0.9.3'
Related
I would like to create a spinner in Android XML, which will have list of the phone codes (ex. USA - +1), and after choosing the phone code at the bottom I want a program to show the country name of the chosen phone code. It should work automatically, which means whenever I change the phone code, it will change the name of the Country.
Thanks!
you can use 3rd party library for this.
https://github.com/hbb20/CountryCodePickerProject/blob/master/README.md?fbclid=IwAR1tz_D3PTEUyy2-zaGG0QTZWda_8ss9nbSml-z7zyI3gULLFsibIlRhujs
if you want to you own program you can try i can help if any difficult situation.
Overview
AFAIK on Android you have twi ways to set the texts of your application:
You can use string.xml with different locales
You can download strings from server and set every label with a setText(language.text) but it will be a pain
The problem might sussist if you have to change a text of your published application without re-publishing it; for example if you want to change for a specific translation a small text without any functionality change. (ie: you might notice that you wrote "Take picure" instead of "Take picture").
Library
i18next is a good library to manage translations dinamically from server, but you still have to add the text for each label you got.
So, my question is
Still AFAIK, there is no way to do it natively, but is there a low level library or a workaround that allows to replace a string in your string.xml with some downloaded text?
Another option could be to make our label text to point instead of at #string/myValue to something like #myresource.pathtovalue.
Honestly I think this could be an huge improvement for application, is there something useful?
I hope this question isnt going to be down-flagged for not showing some actual code, but thats the core of this situation. I simply have no clue where to start to solve this issue, even after trying to use several combinations of keywords on both Google, and here on SO.
My client suddenly decided that half of the Android App I'm developing for him has to be Chinese, so after I have made some changes in the Database so some fields can take in Simplified Chinese character sets, I need to make sure that my client (living in holland) only uses those characters in that particular EditText field in the app. (There are more Database fields that now only allow Simplified Chinese, however these values come from a dropdown list in the app, so I dont need to worry about wrong characters for them).
So how would one make sure that only Simplified Chinese is used in an EditText field?
Here is a project in Ruby that attempts to detect whether characters are Traditional Chinese, Simplified Chinese, or Japanese (maybe others?): https://github.com/jpatokal/script_detector
This detection is based on the Unihan Database, in which there is a file called Unihan_Variants.txt. (Download zip file containing this text file here.)
Conceivably, you could parse the txt file into a lookup table and check the unicode value as the text is entered during onTextChanged() for your EditText. However, the readme on the project linked above states: "It is important to understand that this requires long sections of text to work reliably, since a single character or even several characters may be valid Japanese, traditional Chinese and simplified Chinese simultaneously." So, weeding out characters on an individual basis might prove difficult.
I want to validate phone number.
Phone Number = countryCode+areaCode+PhoneNumber.
I want to know what is the standard minimum and maximum length of Phone Number so i could validate it.
-thanks
Try this regex:
^[+]?[0-9]{10,13}$
Or this:
PhoneNumberUtils.isGlobalPhoneNumber("+912012185234");
It would depend on if you are accepting any country code or are looking for specific country code/s.
Then how many digits you are expecting for area code and then the actual phone number and whether these are being fetched as separate variables or one string.
So after answering these question. You can use (test your code) regex (learn how to use it), (and as #Basil has suggested), but vary the length (and possibly digits, if there are limited country codes) accordingly.
Here is a good answer to using regex in android.
This question is not specific to Android but I have included the tag.
I need to be able to store phone numbers in some sort of standard form (ideally a string) where equality can be tested/evaluated quickly (hence a string would be ideal)
I found some answers already, the best ones pointed to http://developer.android.com/reference/android/telephony/PhoneNumberUtils.html (I'm fine with using a library to do it for me)
BUT this isn't really good enough, I've tried a variety of format numbers, learnt about the Editable factory to use some of the static methods in that class, but they don't seem to return the form I was expecting.
I was expecting something like a phone-number-hash, that two inputs representing the same number would yield the same in this "standard form" and that one could dial this standard form and be fine. I thought that all the various +s and whatnot would be short-hands for this standard form.
I'm not sure if such a thing exists now.
I understand that some things mean "current area" (or country) which is why land-lines can ommit area codes, I expected a function that would return the format for the current location (but this doesn't apply to mobiles, if it were a land line to prepend the area code for example, this would be (closer) to the "standard form" I keep assuming exists)
I am pretty sure that some full-form for phone numbers exists, thinking about how the telephone system works (which I infer I admit) there ought to be a form that identifies a number uniquely across the whole planet, and when this is not the case (such as local calls from land-lines without area codes) it is an optimisation.
So I have two questions:
How can I "expand" a phone number to a unique string for that number, such that any alternate forms of writing that number (with spaces, an 0 or +44....) "expand" to this unique number?
Are there any ISO(/IEC?) (what's the O stand for?) standard documents with drafts open to the public? I've read the Wikipedia page (ages ago, I've spent so many hours wiki-browsing, and opened hundreds of tabs) but it covers history, or some information on formatting), I'd like to know more about the thing I've taken for granted now for some 8 years or so.
Additionally, why is Windows Phone 8 a tag? To make the 12 proud Lumina owners not feel left out? (It was suggested as a tag!)
Addendum
Unfortunately Any API in android to normalize phone number there are no solutions there (this includes libphonenumber) and my quest to find out has lead to some interesting reads:
http://en.wikipedia.org/wiki/Panel_switch
http://en.wikipedia.org/wiki/Nonblocking_minimal_spanning_switch
http://en.wikipedia.org/wiki/Telephone_exchange
and I still cannot conclude there isn't some "full form" for numbers.
I dare not create a solution that simply swaps +44 for an 0 and such.
After reading your question, I was reminded of Google's library called libphonenumber. Its Google's common library for parsing, formatting, storing and validating international phone numbers. It does the following things ( some of which seem what you might be able to use):
Parsing/formatting/validating phone numbers for all countries/regions
of the world.
getNumberType - gets the type of the number based on
the number itself; able to distinguish Fixed-line, Mobile, Toll-free,
Premium Rate, Shared Cost, VoIP and Personal Numbers (whenever
feasible).
isNumberMatch - gets a confidence level on whether two
numbers could be the same.
isPossibleNumber - quickly guessing whether a number is a possible
phonenumber by using only the length information, much faster than a
full validation.
isValidNumber - full validation of a phone number
for a region using length and prefix information.
AsYouTypeFormatter - formats phone numbers on-the-fly when users enter each digit.
PhoneNumberOfflineGeocoder - provides geographical information related to a phone number.
As far as international format of phone number is concerned, E.164 format is an recommended by International Telecommunication Union. It defines a numbering plan for the world-wide public switched telephone network and is a general format for international telephone numbers ( usually stats with + followed by country code, Area code and the number).
Using the above library, validity of all the phone numbers can be checked if you mention the international code along with the phone number ( example 1 for US & Canada). If you don't have the code but you know the country's name for which you want to check the number, then also you can validate. You can also convert all the valid numbers of 1 standard E.164 format using this library. You can also 'expand' a number in Local National format of that particular country. You can save it as String as well. Although it does use PhoneNumberUtils that you mentioned in your question.
I am not sure if this is what you are looking for but I hope this information helps you.