【发布时间】:2018-08-15 05:40:10
【问题描述】:
我是 Xamarin 的新手。我有一个 Xamarin Forms 应用程序,它需要为 ios 和 android 实现电话服务。
这是我在.net共享项目下的界面:
using System;
using System.Collections.Generic;
using System.Text;
namespace CallMeMaybe.Services
{
public interface ICallService
{
void MakePhoneCall(string number);
}
}
这是视图模型中的命令方法:
private void OnCall(object s)
{
DependencyService.Get<ICallService>().MakePhoneCall(Convert.ToString(s));
}
这是我的Android Call Service,需要实现MakePhoneCall方法
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?
}
}
}
如何在我的 Android 方法中启动拨号活动?这是一个服务类而不是 Activity 类,所以我没有扩展 Activity。
【问题讨论】:
标签: android xamarin xamarin.forms xamarin.android