【问题标题】:Android.Content.ActivityNotFoundException: <Timeout exceeded getting exception details> Xamarin C#Android.Content.ActivityNotFoundException:<超时获取异常详细信息> Xamarin C#
【发布时间】:2018-12-15 01:05:53
【问题描述】:

最近我尝试在 Visual Studio 2017 中使用 Xamarin 学习 android 编程 我写了一个简单的应用程序来拨打电话,但是当我点击呼叫按钮时,几天前它给出了这个执行错误,但现在我得到了这个错误 我确实在清单文件中允许了 CALL_PHONE 原谅我英语不好 如果有人知道如何解决这个问题,请告诉我我会很高兴 这是我的代码 .cs

using Android.App;
using Android.Widget;
using Android.OS;
using Android.Content;


namespace Dialer.app
{
    [Activity(Label = "Dialer.app", MainLauncher = true)]
    public class MainActivity : Activity
    {
        Button btnCall;
        ListView txtViewNumbers;
        EditText txtUnumber;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            btnCall = FindViewById<Button>(Resource.Id.button1);
            txtViewNumbers = FindViewById<ListView>(Resource.Id.listView1);
            txtUnumber = FindViewById<EditText>(Resource.Id.editText1);
            string phone = txtUnumber.Text;
            btnCall.Click += delegate
            {
                var callDialog = new AlertDialog.Builder(this);
                callDialog.SetMessage("Dial This Number? " + phone);


                callDialog.SetPositiveButton("ok", delegate
                {
                    var callIntent = new Intent(Intent.ActionCall);
                    callIntent.SetData(Android.Net.Uri.Parse(phone));
                    StartActivity(callIntent); //i get error in this line
                });


                callDialog.SetNeutralButton("Cancel", delegate { });
                callDialog.Show();
            };

        }
    }
}

【问题讨论】:

    标签: c# xamarin xamarin.android


    【解决方案1】:

    未找到处理 Intent 的 Activity { act=android.intent.action.CALL .....

    您在电话号码上缺少tel: 前缀:

    var callIntent = new Intent(Intent.ActionCall);
    callIntent.SetData(Android.Net.Uri.Parse("tel:" + phone));
    StartActivity(callIntent);
    

    但是,在最新的 API 级别中,CALL_PHONE 是被撤销的权限:

    权限拒绝:启动 Intent { act=android.intent.action.CALL dat=tel:xxx-xxx-xxxx

    您需要用户通过系统拨号器接受号码,而不是被允许直接拨打号码,这是通过ACTION_DIAL完成的:

    var callIntent = new Intent(Intent.ActionDial);
    callIntent.SetData(Android.Net.Uri.Parse("tel:" + "555-555-1212"));
    StartActivity(callIntent);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多