Check Mobile App
Read now

How to open a dialer with a phone number

Save

You must have seen several apps which opens a dialer with a specific number or even directly make a call to them. This functionality is quite easy to implement and very useful.

 

Let us look at the different ways to do the required task.

1) If you have a TextView which is displaying a phone number and you want to call on that number on a tap then this can be achieved by adding the autoLink attribute to the TextView.

But this one comes with a drawback that it doesn’t work for all kind of phone numbers. For example,  a phone number of 11 numbers won’t work with this option. The solution is to prefix your phone numbers with the country code (09876543210 won’t work but +1569876543210 will work).

This doesn’t even need permission. Just add the attribute and you are good to go.

 

2) You can do the same programmatically also. The Intent.ACTION_DIAL will take you to the dialer screen all you need to do is add the phone number in the data.

The ‘tel:’ prefix is required, otherwise the following exception will be thrown: java.lang.IllegalStateException: Could not execute method of the activity.

 

3) If you want to directly make a call then this needs a CALL_PHONE permission. Add the permission in your AndroidManifest and change the ACTION_DIAL to ACTION_CALL in the above method.

 

Thank you very much. This is Vedesh Kumar signing off.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

Deniel Kerr

Owner and Founder. Opencart

Talk to Sales
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home