Вопрос

I have the following onClickListener():

phonereserveListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (phone!=null){
            String url = "tel:"+phone;
            Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
            startActivity(callIntent);
            }
            else{
                Toast.makeText(getActivity(), "Phone number not available", Toast.LENGTH_LONG).show();
            }

        }

    };

My problem is that i get the phone numbers from an webservice call and some numbers are null (no problem cause the toast makes its appearance), some numbers are normal, some examples:

" 05 07 06-3141"
" 05 07 06-3171"

But some numbers come as 2 in one. Example:

"Shop:  05 07 06-3121\nBar:  05 07 06-3122"

And for this number if I try to call the intent.ACTION_CALL the phone calls something like:

"746705070631212270507063122"

because he takes S=7 h=4 o=6 etc.

What can I do to take the 2 numbers from the String and then make an intent chooser to choose the correct number (Shop/bar)?

PS: The list of phonenumbers that comes is dynamic, and implemented through a webservice, so it will always change

Это было полезно?

Решение

I had a similar problem and i solved extracting the phone number from the string with this library:

http://code.google.com/p/libphonenumber/

public static ArrayList<String> extractPhoneNumber(String content) {

    ArrayList<String> numbers = new ArrayList<String>(0);

    PhoneNumberUtil instance = PhoneNumberUtil.getInstance();

    //Change IT with your contry code
    Iterable<PhoneNumberMatch> matches = instance.findNumbers(content, "IT");

    Iterator<PhoneNumberMatch> iterator = matches.iterator();

    while (iterator.hasNext()) {
        numbers.add(instance.format(iterator.next().number(), PhoneNumberFormat.INTERNATIONAL));
    }

    return numbers;
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top