Hidel the device dialer

Fábio Miranda 21 Reputation points
2022-11-07T01:34:27.63+00:00

Hi,

I was going through the training basics (Create a cross-platform app with .NET MAUI) and I wanted to be able to close the dialer if it's open.

For example, I use the method PhoneDialer.Open(string number) to open the dialer, but if the user clicks in another UI element of the page (lets say, a button to cancel the operation), I want to close the dialer is there is some open.

How to achieve that given the low level of control in the classe PhoneDialer?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,231 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 39,391 Reputation points Microsoft Vendor
    2022-11-08T01:56:15.063+00:00

    Hello,

    It is no possible to set any UI element on Phone Dialer to close it, due to it is the highest priority system application.

    You could use the following code to confirm to the user that you want to open the dialer.

       private async void OnCounterClicked(object sender, EventArgs e)   
       {  
           string phoneStr = "000-000-0000";  
           bool answer = await DisplayAlert("Question?", $"Would you like to open phone Dialer with {phoneStr}?", "Yes", "No");  
           if (answer)  
           {  
               if (PhoneDialer.Default.IsSupported)  
                   PhoneDialer.Default.Open(phoneStr);  
           }  
       }  
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful