0

我正在使用 Xamarin 为 Android 构建呼叫转移或呼叫转移应用程序。我在网上找到了这段代码,我认为它是负责呼叫转移操作的代码:

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

所以我有几个问题:

  1. 此代码是否是呼叫转移操作所需的正确代码?我希望有一个资源来解释这段代码中的每个函数和行的作用。

  2. 因为它是特定于 android 的代码,所以我觉得我必须将它放在我的 Xamarin 解决方案的 android 项目中。我说得对吗?

提前致谢!

4

1 回答 1

0

此代码是否是呼叫转移操作所需的正确代码?

不,如果您的代码使用的是 java,它应该是:

//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);

您可以阅读本文以了解意图是什么。

因为它是特定于 android 的代码,所以我觉得我必须将它放在我的 Xamarin 解决方案的 android 项目中。我说得对吗?

是的,您需要将其转换为 C#:

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

Intent intentCallForward = new Intent(Intent.ActionDial);

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

intentCallForward.SetData(uri2);

StartActivity(intentCallForward);
于 2018-06-18T02:36:42.977 回答