Xamarin Forms: Call a number directly?

RicardoSRicardoS ESMember ✭✭✭

Ok, this may be a bit difficult to explain for me, but i'll try my best.

We (and by 'we' I mean 'my higher ups') want to phone a specific number trough our app. That is the easy part.
The problem is that, when the button is pushed, prompts you to the telephone editor screen, were you can delete digits, make the call or cancel.
We (refer to the previous parentheses) don't want that. We need to, when the user presses the aforementioned button, call that number directly.
With no intermediate steps.

If this is not possible, please give us a thorough explanation. I'm a bit in a pickle here.

Kind regards

Best Answers

Answers

  • RicardoSRicardoS ESMember ✭✭✭

    @JohnHair Thank you for your response.

    I hope this quench my higher ups thirst for solutions.

  • bifedefrangobifedefrango Member ✭✭

    I don't know if this helps or if this is what you're already doing but...

    stackoverflow.com/questions/37551576/how-to-make-a-phone-call-in-xamarin-forms-by-clicking-on-a-label

  • JohnHJohnH GBMember ✭✭✭✭✭

    @bifedefrango said:
    I don't know if this helps or if this is what you're already doing but...

    stackoverflow.com/questions/37551576/how-to-make-a-phone-call-in-xamarin-forms-by-clicking-on-a-label

    Ricardo was asking specifically how to not display the dialler.

  • RicardoSRicardoS ESMember ✭✭✭

    @bifedefrango Yeah, what JohnHair said.

    I tried that one before.

  • RicardoSRicardoS ESMember ✭✭✭

    @JohnHair If anything we'll go back to the "show the dialer".

  • bifedefrangobifedefrango Member ✭✭

    I think that @JohnHair is right then, when he said "That isn't possible, can you imagine the number of apps with a hidden rogue dialler calling premium rate numbers if it was possible?" ...

    And anyway I think you should reconsider because the user may press the "call" button by accident and he's not given the choise if he really wants to do it...

  • RicardoSRicardoS ESMember ✭✭✭

    @bifedefrango I know.

    The problem is that I have to search for it thoroughly so that the higher ups understand that it cannot be done.

  • RicardoSRicardoS ESMember ✭✭✭

    Thank you, @deczaloth .
    I'll try later.

  • NMackayNMackay GBInsider, University mod

    @RicardoS said:
    @bifedefrango I know.

    The problem is that I have to search for it thoroughly so that the higher ups understand that it cannot be done.

    Tell the higher ups it's a dumbass idea and if this is a consumer app, people will soon uninstall it.....Yeah, I know you can't say that :smile:

  • RicardoSRicardoS ESMember ✭✭✭

    @deczaloth What is this for?
    Android?
    iOS?
    Forms?

  • RicardoSRicardoS ESMember ✭✭✭

    No, @NMackay . It's not a consumer app. It's, ehh... for another company?
    That's all I can tell.

    @NMackay said:

    Tell the higher ups it's a dumbass idea and if this is a consumer app, people will soon uninstall it.....Yeah, I know you can't say that :smile:

    But I'll keep those words in mind :grin:

  • NMackayNMackay GBInsider, University mod

    @RicardoS said:
    @deczaloth What is this for?
    Android?
    iOS?
    Forms?

    It's Xamarin Android code, should be easy enough to spot that.
    https://developer.xamarin.com/api/member/Android.Content.Context.StartActivity/p/Android.Content.Intent/

  • RicardoSRicardoS ESMember ✭✭✭

    @NMackay
    Sorry, I'm a bit thick when it comes to identify code...

    do you think we can use that in an interface? Like this:

    [assembly: Dependency (typeof (PhoneCallTask_Droid))]
    namespace Conductores.Droid {
    public class PhoneCallTask_Droid : IPhoneCallTask {
    public PhoneCallTask_Droid () { }

        public void MakePhoneCall (string number, string name = null) {
            if (string.IsNullOrWhiteSpace (number)) {
                throw new ArgumentException ("number");
            }
            Intent dialIntent = new Intent (Intent.ActionCall, CreateNSUri (number));
            Forms.Context.StartActivity (dialIntent);
        }
    
        private Uri CreateNSUri (string phoneNumber) {
            return Uri.Parse ($"tel:{phoneNumber}");
        }
    }
    

    }

  • RicardoSRicardoS ESMember ✭✭✭

    Ooops, i forgot the forms interface:

    namespace Conductores {
    public interface IPhoneCallTask {
    void MakePhoneCall (string number, string name = null);
    }
    }

  • NMackayNMackay GBInsider, University mod

    This link might help, I really would test this on hardware and check how specific OS version cope.
    https://stackoverflow.com/questions/33880505/make-phone-call-directly-xamarin-forms

  • RicardoSRicardoS ESMember ✭✭✭

    Thank you @NMackay

  • deczalothdeczaloth DEMember ✭✭✭

    @JohnHair
    That isn't possible...

    Well, i am not sure about iOS, but in android it IS possible, as you can yourself see if you try the code i shared above (at least that is working on my side testing with a Samsung S7).

    @JohnHair
    ...can you imagine the number of apps with a hidden rogue dialler calling premium rate numbers if it was possible?

    I beg your pardon, but i do not understand that. How could an App make calls to "premium rate numbers" without you knowing, and even if an app would do that (i still do not see the point) you can always hang up... or am i missing something?

    @NMackay said:
    Tell the higher ups it's a dumbass idea and if this is a consumer app, people will soon uninstall it.....Yeah, I know you can't say that :smile:

    @NMackay, why exactly is that a "dumbass idea"? I am using the code i shared above in my own App (my users can store contacts information and call them by tapping a button), and ...well, i would like to know why do you think it is such a bad practice...

  • JohnHJohnH GBMember ✭✭✭✭✭

    @deczaloth said:

    I beg your pardon, but i do not understand that. How could an App make calls to "premium rate numbers" without you knowing, and even if an app would do that (i still do not see the point) you can always hang up... or am i missing something?

    The original poster was asking to make a call without the dialler, what if the button says something like 'Play Game' and calls a premium rate number? The user wouldn't know.

    Tell the higher ups it's a dumbass idea and if this is a consumer app, people will soon uninstall it.....Yeah, I know you can't say that :smile:

    @NMackay, why exactly is that a "dumbass idea"? I am using the code i shared above in my own App (my users can store contacts information and call them by tapping a button), and ...well, i would like to know why do you think it is such a bad practice...

    So it does display a dialer? It must do to be able to cancel the call.

  • deczalothdeczaloth DEMember ✭✭✭

    @JohnHair said:
    So it does display a dialer? It must do to be able to cancel the call.

    It does launch the Android phone app, but you can not edit the number since the call is automatically made. You can hang up, thou.

    @JohnHair said:
    The original poster was asking to make a call without the dialler...

    I think the point was that @RicardoS wanted not to let the user editing the number to call:

    @RicardoS
    The problem is that, when the button is pushed, prompts you to the telephone editor screen, were you can delete digits, make the call or cancel.

  • JohnHJohnH GBMember ✭✭✭✭✭

    @deczaloth said:

    @JohnHair said:
    So it does display a dialer? It must do to be able to cancel the call.

    It does launch the Android phone app, but you can not edit the number since the call is automatically made. You can hang up, thou.

    @JohnHair said:
    The original poster was asking to make a call without the dialler...

    I think the point was that @RicardoS wanted not to let the user editing the number to call:

    @RicardoS
    The problem is that, when the button is pushed, prompts you to the telephone editor screen, were you can delete digits, make the call or cancel.

    As you point out they can cancel the call, he did mention he didn't want to delete digits, make the call or cancel.

  • deczalothdeczaloth DEMember ✭✭✭

    @JohnHair
    As you point out they can cancel the call, he did mention he didn't want to delete digits, make the call or cancel.

    I get your point :P

  • NMackayNMackay GBInsider, University mod
    edited February 14

    @deczaloth said:

    @JohnHair
    That isn't possible...

    Well, i am not sure about iOS, but in android it IS possible, as you can yourself see if you try the code i shared above (at least that is working on my side testing with a Samsung S7).

    @JohnHair
    ...can you imagine the number of apps with a hidden rogue dialler calling premium rate numbers if it was possible?

    I beg your pardon, but i do not understand that. How could an App make calls to "premium rate numbers" without you knowing, and even if an app would do that (i still do not see the point) you can always hang up... or am i missing something?

    @NMackay said:
    Tell the higher ups it's a dumbass idea and if this is a consumer app, people will soon uninstall it.....Yeah, I know you can't say that :smile:

    @NMackay, why exactly is that a "dumbass idea"? I am using the code i shared above in my own App (my users can store contacts information and call them by tapping a button), and ...well, i would like to know why do you think it is such a bad practice...

    I assumed the app was going to dial without the user been aware or not been obvious. Dumbass was a tad strong but was meant in jest and yes, if your re-inventing WhatsApp etc then all good, there are API's to the dialler. As an end user I just always like to be presented with the control (Pop native dialler or default email client etc) but I retract the dumbass bit, it just wasn't obvious from the original post. No harm done.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @RicardoS @deczaloth @JohnHair @NMackay My 2 cents here:

    I started my mobile development in 2010 with Windows Phone. iPhone was already established then and Android was just picking up.

    Yes, at that time all 3 platforms allowed to call direct dialing API from an app. Soon after they got complaints and all 3 platforms started blocking access to direct call APIs and forced route through the built-in dialer app.

    Ever since I was hearing the demands / requests / opinions for direct dialing access...nothing happened and no platform budged.

    WhatsApp and Facebook appears to be allowing direct dialing, but that is within their system. They don't call landlines or cellphones.

    I am aware of availability of dialing services for a fee. If someone doesn't want to hit the phone's call button once again, then they may avail those services at cost.

  • NMackayNMackay GBInsider, University mod

    @ShantimohanElchuri said:
    @RicardoS @deczaloth @JohnHair @NMackay My 2 cents here:

    I started my mobile development in 2010 with Windows Phone. iPhone was already established then and Android was just picking up.

    Yes, at that time all 3 platforms allowed to call direct dialing API from an app. Soon after they got complaints and all 3 platforms started blocking access to direct call APIs and forced route through the built-in dialer app.

    Ever since I was hearing the demands / requests / opinions for direct dialing access...nothing happened and no platform budged.

    WhatsApp and Facebook appears to be allowing direct dialing, but that is within their system. They don't call landlines or cellphones.

    I am aware of availability of dialing services for a fee. If someone doesn't want to hit the phone's call button once again, then they may avail those services at cost.

    Yeah, I should add I've only seen the phone API in Android used for monitoring inbound calls etc, the approach posted a link to earlier seems to be the only way.

    https://stackoverflow.com/questions/4816683/how-to-make-a-phone-call-programmatically

  • JohnHardmanJohnHardman GBUniversity mod
    edited February 14

    @JohnHair said:
    As you point out they can cancel the call, he did mention he didn't want to delete digits, make the call or cancel.

    The original post was open to interpretation. My reading of it is that the important bit is that call should be made "With no intermediate steps", with the mention of cancellation being a "problem" referring to cancelling before the call is initiated, not terminating a call in progress. @RicardoS - can you confirm that is what you meant please.

    The code posted by @deczaloth above does work - initiating a call without the intermediate step. On recent versions of Android the user does explicitly need to grant permission to the app for this to happen (I currently use James Montemagno's plugin for this), so on those Android versions the app cannot start making calls without the user having granted permission for it to do so. The user can subsequently revoke permission if so desired.

    I am undecided regarding whether this is a good idea or not. The app that I am working on can make calls. I am still looking at the use cases before making a final decision about whether or not to include the intermediate dialler step. I might even switch depending on the Android version, so that the versions requiring permission to be granted can skip the dialler step, but versions that don't require permission do show the dialler. Options, options...

  • NMackayNMackay GBInsider, University mod

    @JohnHardman said:

    @JohnHair said:
    As you point out they can cancel the call, he did mention he didn't want to delete digits, make the call or cancel.

    The original post was open to interpretation. My reading of it is that the important bit is that call should be made "With no intermediate steps", with the mention of cancellation being a "problem" referring to cancelling before the call is initiated, not terminating a call in progress. @RicardoS - can you confirm that is what you meant please.

    The code posted by @deczaloth above does work - initiating a call without the intermediate step. On recent versions of Android the user does explicitly need to grant permission to the app for this to happen (I currently use James Montemagno's plugin for this), so on those Android versions the app cannot start making calls without the user having granted permission for it to do so. The user can subsequently revoke permission if so desired.

    I am undecided regarding whether this is a good idea or not. The app that I am working on can make calls. I am still looking at the use cases before making a final decision about whether or not to include the intermediate dialler step. I might even switch depending on the Android version, so that the versions requiring permission to be granted can skip the dialler step, but versions that don't require permission do show the dialler. Options, options...

    Also worth noting that calling in Android has different permission levels, on later versions it falls under "protected/dangerous permissions" and you explicitly have to request permission regardless of manifest (having had to implement this).

  • JohnHardmanJohnHardman GBUniversity mod

    @NMackay said:
    Also worth noting that calling in Android has different permission levels, on later versions it falls under "protected/dangerous permissions" and you explicitly have to request permission regardless of manifest (having had to implement this).

    Exactly - the user has to explicitly grant the permission at run-time, so apps cannot run amok on those later Android versions. If the user does grant that permission, the user can revoke it again.

  • RicardoSRicardoS ESMember ✭✭✭

    Guys, please calm down.
    It's not that urgent nor important.
    Just a secondary feature.
    Our app does not depend on this.

    I almost made a haiku :yum:

  • RicardoSRicardoS ESMember ✭✭✭

    Ok, everything works as expected.
    Thank you to all for the help and this awesome time.

    Seriously though, this whole thread was a riot. :lol:

Sign In or Register to comment.