[英]Phone number sanitizer for intent.ACTION_CALL
我有以下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();
}
}
};
我的問題是,我從網絡服務呼叫中獲得電話號碼,有些號碼為空(沒問題,因為烤面包露面了),有些號碼是正常的,例如:
" 05 07 06-3141"
" 05 07 06-3171"
但是有些數字是二合一的。 例:
"Shop: 05 07 06-3121\nBar: 05 07 06-3122"
對於這個號碼,如果我嘗試撥打intent.ACTION_CALL,電話會撥打類似以下內容:
"746705070631212270507063122"
因為他需要S = 7 h = 4 o = 6等等
我該怎么做才能從字符串中提取兩個數字,然后讓意圖選擇器選擇正確的數字(商店/酒吧)?
PS:出現的電話號碼列表是動態的,並且是通過Web服務實現的,因此它將始終更改
我有一個類似的問題,我解決了使用此庫從字符串中提取電話號碼的問題:
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 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.