Reputation: 23503
I'm having trouble making a phone call with Android. The problem lies in the fact that the number I am getting has parentheses around the area code, ie (206) 555 1234
. Here is the code I'm using:
final String phone = listdata.getPhone();
...
ImageButton phoneButton = (ImageButton) this.findViewById(R.id.phoneButton);
phoneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Uri phoneNum = Uri.parse(phone);
Intent phoneIntent = new Intent(Intent.ACTION_CALL, phoneNum);
//phoneIntent.setData();
DetailActivity.this.startActivity(phoneIntent);
}
});
Here is the error I'm getting:
09-27 10:01:45.771: E/AndroidRuntime(23422): FATAL EXCEPTION: main
09-27 10:01:45.771: E/AndroidRuntime(23422): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=(206) 623-1922 }
09-27 10:01:45.771: E/AndroidRuntime(23422): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
09-27 10:01:45.771: E/AndroidRuntime(23422): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
09-27 10:01:45.771: E/AndroidRuntime(23422): at android.app.Activity.startActivityForResult(Activity.java:3248)
09-27 10:01:45.771: E/AndroidRuntime(23422): at android.app.Activity.startActivity(Activity.java:3359)
09-27 10:01:45.771: E/AndroidRuntime(23422): at com.uie.top25.seattle.DetailActivity$2.onClick(DetailActivity.java:94)
09-27 10:01:45.771: E/AndroidRuntime(23422): at android.view.View.performClick(View.java:3526)
09-27 10:01:45.771: E/AndroidRuntime(23422): at android.view.View$PerformClick.run(View.java:14133)
09-27 10:01:45.771: E/AndroidRuntime(23422): at android.os.Handler.handleCallback(Handler.java:605)
09-27 10:01:45.771: E/AndroidRuntime(23422): at android.os.Handler.dispatchMessage(Handler.java:92)
09-27 10:01:45.771: E/AndroidRuntime(23422): at android.os.Looper.loop(Looper.java:137)
09-27 10:01:45.771: E/AndroidRuntime(23422): at android.app.ActivityThread.main(ActivityThread.java:4697)
09-27 10:01:45.771: E/AndroidRuntime(23422): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 10:01:45.771: E/AndroidRuntime(23422): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 10:01:45.771: E/AndroidRuntime(23422): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
09-27 10:01:45.771: E/AndroidRuntime(23422): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
09-27 10:01:45.771: E/AndroidRuntime(23422): at dalvik.system.NativeStart.main(Native Method)
Is there anything I can do, short of changing the number source?
Upvotes: 0
Views: 303
Reputation: 6699
I'm not sure if Android has changed in the last 8 months to accomodate this, but the problem is not the formatting of the number. Android handles parentheses, space, and dashes just fine. The problem is the lack of the prefix "tel:" in the Uri.
Uri phoneNum = "tel:" + Uri.parse(phone);
Upvotes: 1
Reputation: 14472
Be careful or you'll build something that will work for some geographic areas and not others. Consider this:
0044(0)123456789. UK international number. The zero and the brackets must be removed or the number will not dial.
(0)123456789. UK national number. The brackets, but not the zero, must be removed or the number will not dial.
(0)123 456789. US national number but for a local call. In some regions, the area code must be removed if the call is in the same region. So some regions would accept 123456789, others would accept only 456789.
And it goes on. Mobile numbers are particularly difficult to handle in some countries, e.g. Italy.
Start off your research by looking at the E.164 specification.
Upvotes: 1
Reputation: 23665
You'll have to change the number source because the ACTION_CALL intent does not understand the number otherwise. So either you change your number or you can wait until Google changes Android to fit your needs :-)
Upvotes: 2