Issue
I'm new to Xamarin. I have a Xamarin Forms App which needs to implement the phone call service for ios and android.
This is my Interface under the .net shared proj:
using System;
using System.Collections.Generic;
using System.Text;
namespace CallMeMaybe.Services
{
public interface ICallService
{
void MakePhoneCall(string number);
}
}
This is the command method in the view model:
private void OnCall(object s)
{
DependencyService.Get<ICallService>().MakePhoneCall(Convert.ToString(s));
}
This is my Android Call Service that needs to implement the MakePhoneCall method
using Android.App;
using Android.Content;
using CallMeMaybe.Droid.Services;
using CallMeMaybe.Services;
using Xamarin.Forms;
[assembly: Dependency(typeof(CallService))]
namespace CallMeMaybe.Droid.Services
{
[Activity(Label = "CallService")]
public class CallService : ICallService
{
public void MakePhoneCall(string number)
{
var uri = Android.Net.Uri.Parse("tel:" + number);
var intent = new Intent(Intent.ActionCall, uri);
//Start Activity here?
}
}
}
How can I start the dial activity in my Android Method? This is a service class not an Activity class so I'm not extending Activity.
Solution
First of all this class is not an activiry, so you need to remove [Activity(Label = "CallService")]
public void MakePhoneCall(string number)
{
var intent = new Intent(Intent.ActionCall, Android.Net.Uri.Parse(
"tel:" + Uri.EscapeDataString(phoneNumber)));
Android.App.Application.Context.StartActivity(intent);
}
This intent will open calling app and start call
By executing StartActivity(intent)
you command Android to open Calling App Activity and start call
Answered By - Dmitry Zinoviev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.