I am PhoneNumberUtil to see phone numbers i enter into a text view and then send them a message. However it does not work as my Numbers are Formated with a '+44 ...' whereas PhoneNumberUtils needs numbers to be written like '44...'. Does anyone know how i can fix this?
If I am understanding your issue correctly, it sounds like you want to strip just the numbers from a string to leave an unformatted number for the formatter to work with.
Related
In my application users enters mobile number's country code with '+' symbol. Right now I am checking for + symbol. If they enter '+INDIA', according to my code this is correct. But according to logic this is wrong. They needs to enter '+91'. Means they can enter only 1, 2 or 3 digit number with '+' symbol. for example '+1', '+91' or '+234'. How I can achieve this type of validation in android?
You could write your own Pattern to check the format. I could give you the example, but I think the site I linked explains it much better.
It should probably start with something like \+\d\d?\d?
You could try using Google's own implementation of Phone Numbers or this xml list.
Hope it helps !
I have the following idea:
In German we have four extra letters (ä, ö, ü, ß) and I don't know any other language which has these vocals but I think French people with their accents also know this problem. We have a lot of apps in the Google Play store for cities, bus stations, trains and other stuff like that. Now it is really exhausting that we always have to write these letters if we are on the go. It would be much easier to write Munchen (=München [de] = Munich [en]), Osterreich (Österreich [de] = Austria [en]) or something like Uberwasserstrasse (Überwasserstraße [de] = Over-Water-Street [en]). So my question is now:
A lot of apps show suggestions for our just typed word. I think in the code it is something like this:
String current = editText.getText().toString();
db.lookUp(current); // Of course SQL statement
Can we hook this so that Android thinks that we have typed an ä, ö, ü, ß if we write an a, o, u, ss and the system looks for words with one of these vowels and suggests both? Here I do not want to ask for code - I want to discuss if we are able to write a hack or hook for the Android system. Also, root-rights can be assumed with the solution. I'm looking forward to your ideas.
You could do this the other way around, by "normalizing" typed characters into their related non-diacritical versions. You can use the java.Text.Normalizer class for this. A good snippet can be found in this article:
public static String removeAccents(String text) {
return text == null ? null :
Normalizer.normalize(text, Form.NFD)
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
}
When applied to "Münich", this returns "Munich". That way, you can use a simple string comparison using these normalized versions.
This wouldn't work for "ß" though. If that's the only special case, you could handle it separately.
What you are looking for is called accent-insensitive collating sequence. SQLite's COLLATE operator can be used to do such searches, but I learned from another post that there might be bugs you'll need to look out for.
I have the following code that was working fine in Android 2.2 to format phone numbers by 555-555-5555, but in 4.x it is formatting them in 555555-555.
inputPhoneNumber = (EditText) findViewById(R.id.inputPhoneNumber);
inputPhoneNumber.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
Any suggestions on how to fix it?
There is another android class specially for formatting phone number PhoneNumberUtils
and some methods you can use:
formatNumber(String source) Breaks the given number down and formats
it according to the rules for the country the number is from.
formatNumber(Editable text, int defaultFormattingType) Formats a
phone number in-place.
Chect it out.
The comment by #learningslowly helped, but I found it to be still incomplete. The full allowed digits string needed for correct & 'normal' format is:
android:digits="0123456789()-+ "
I was previously missing the minus, plus, and space.
I am getting some strings from json. My string contains special characters like "æ" from Næstved an many more like "ø" from køkken. But When I set Text these strings to ant textview, I get my strings printed in unusual way.
Example: For køkken I get kø ;kken.
I think I need to encode or decode my string somewhere but where I don,t know.
Please help.
Thanks in advance
The displayed version of your string represents an HTML encoded entity. You might want to verify that it is not coming in this way in your JSON data, but in any case, to decode it you can use the StringEscapeUtils.unescapeHtml4 method from Apache Commons Lang:
final String escaped = "køkken";
System.out.println(StringEscapeUtils.unescapeHtml4(escaped));
Output:
køkken
Did you check out the Latin Coding for your characters? I know the Ash character can be coded with æ and will show up æ in the browser.
Here is the a list of codes
Hope this helps!
I'm trying to get TextToSpeech to speak alphanumeric references in the Android emulator. If I have a string such as "31NAA123", then I insert spaces between all the characters and then submit it to the speak method. It copes OK with most letters but stumbles on the 'A's, they come out as barely audible very short "ah"s, almost as short as clicks. I've tried replaceAll("A", "AY") which comes out as "ay, why". I've tried most speech rates down to 0.3f - nothing works. I'm using a UK locale to give a British accent. I'd be grateful if anyone has any useful suggestions.
(I suspect 'i' will give similar problems, 'o' seems to be OK)
Have you tried inserting multiple points after the letters? Seems to work pretty well for me:
String s = "a.. b.. c..";
Or even slower:
String s = "a... b... c...";