我是Xamarin的新手。我有一个Xamarin Forms App,它需要实现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呼叫服务,需要实现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方法中启动拨号活动?这是服务类,而不是活动类,因此我不会扩展活动。
答案 0 :(得分:1)
首先,该课程不是活动课程,因此您需要删除def create(conn, %{"company" => company_params}) do
case Company.insert(conn.assigns.current_user, company_params) do
{:ok, _company} ->
redirect(conn, to: company_path(conn, :index))
{:error, changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def update(conn, %{"id" => company_id, "company" => company_params}) do
company = Company.get(company_id)
case Company.update(company, company_params) do
{:ok, _company} ->
redirect(conn, to: company_path(conn, :show, company))
{:error, changeset} ->
render(conn, "edit.html", company: company, changeset: changeset)
end
end
[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);
}
,您命令Android打开“呼叫应用活动”并开始呼叫
答案 1 :(得分:0)
现在可以正常工作。使用应用程序上下文开始活动
ERROR in src/app/web-to-backend-interface.service.ts(80,71): error TS2345: Argument of type '{ headers: HttpHeaders; withCredentials: boolean; observe: "response"; responseType: string; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
Types of property 'observe' are incompatible.
Type '"response"' is not assignable to type '"body"'.
src/app/web-to-backend-interface.service.ts(111,52): error TS2345: Argument of type '{ headers: HttpHeaders; withCredentials: boolean; observe: "response"; responseType: string; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
Types of property 'observe' are incompatible.
Type '"response"' is not assignable to type '"body"'.
src/app/web-to-backend-interface.service.ts(195,73): error TS2345: Argument of type '{ headers: HttpHeaders; withCredentials: boolean; observe: "response"; responseType: string; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
src/app/web-to-backend-interface.service.ts(215,72): error TS2345: Argument of type '{ headers: HttpHeaders; withCredentials: boolean; observe: "response"; responseType: string; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
src/app/web-to-backend-interface.service.ts(250,54): error TS2345: Argument of type '{ headers: HttpHeaders; withCredentials: boolean; observe: "response"; responseType: string; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
src/app/web-to-backend-interface.service.ts(290,9): error TS2322: Type 'Observable<ArrayBuffer>' is not assignable to type 'Observable<HttpEvent<any>>'.
Type 'ArrayBuffer' is not assignable to type 'HttpEvent<any>'.
Type 'ArrayBuffer' is not assignable to type 'HttpUserEvent<any>'.
Property 'type' is missing in type 'ArrayBuffer'.
src/app/web-to-backend-interface.service.ts(296,59): error TS2552: Cannot find name 'response'. Did you mean 'Response'?