0

I'm building a call diverting or call forwarding app for android using Xamarin. I found online this segment of code that i think is the code responsible for the call diverting action:

String callForwardString = "**21*1234567890#";
        Intent intentCallForward = new Intent(Intent.ActionDial); // ACTION_CALL
        Uri uri2 = Uri.fromParts("tel", callForwardString, "#");
        intentCallForward.SetData(uri2);
        startActivity(intentCallForward);

So i have couple of questions about it:

  1. Does this code is the right code that i need for the call diverting action? I would love a source that explain what each function and line in this code do.

  2. Because its a code specific for android i have a feeling that i would have to put it in the android project of my Xamarin Solution. Am i right about this?

Thanks in advance!

MetaDude
  • 139
  • 5
  • 14
  • [Here](https://stackoverflow.com/questions/48485068/difference-between-uri-fromparts-and-uri-parse) is about difference between `Uri.fromParts` and `Uri.parse`. We can also use [this](https://stackoverflow.com/a/10510634/8632294) to call the number directly, the code you provided will call dialing activity, not call the number. – Robbit Jun 18 '18 at 02:39
  • Thank you! this is the answer for the "almost mistake" i would have done. I want to call the number directly and not open the dialing activity – MetaDude Jun 20 '18 at 09:48
  • But your code is opening dialing activity, in my comment, I have provide a link for call the number directly. Please make sure what is your problem. – Robbit Jun 20 '18 at 10:31
  • Yeah that's what i meant by writing: "almost mistake" in the previous comment. I have'nt reached to that part in my program yet because i'm unfamiliar with it, but since you pointed out to me that this segment of code opens the dialing activity instead of calling the number directly (which i think is what i need) you've solved the problam i would have faced if i reached to that part without your help. – MetaDude Jun 20 '18 at 14:26

1 Answers1

0

Does this code is the right code that i need for the call diverting action?

No, if your code is using java, it should be :

//callForwardString  is your phone number
String callForwardString = "**21*1234567890#";
//Use Intent.ACTION_DIAL action to define your intent,
//this action will show you the dialing interface
Intent intentCallForward = new Intent(Intent.ACTION_DIAL);

Uri uri2 = Uri.fromParts("tel", callForwardString, "#");
//put uri into your intent
intentCallForward.setData(uri2);
//jump to dialing interface with the data-uri2 which contains your phone number.
//in your dialing interface, the dialing activity will get the phone number from the data.
startActivity(intentCallForward);

You can read this to understand what intent is.

Because its a code specific for android i have a feeling that i would have to put it in the android project of my Xamarin Solution. Am i right about this?

Yes, you need convert it to C#:

string callForwardString = "**21*1234567890#";

Intent intentCallForward = new Intent(Intent.ActionDial);

Uri uri2 = Uri.FromParts("tel", callForwardString, "#");

intentCallForward.SetData(uri2);

StartActivity(intentCallForward);
Robbit
  • 4,300
  • 1
  • 13
  • 29
  • As i wrote in the title i'm using C# and nothing else. I saw on other source online that because that code is android native code i need to use Dependency Service to connect the code in my Xamarin.Forms project with the android code and project – MetaDude Jun 20 '18 at 09:42