MatriX vNext无法在Android中连接

时间:2019-12-11 05:06:25

标签: c# android xamarin xmpp agsxmpp

我正在尝试使用Matrix.vNext包在Xamarin中创建一个简单的XMPP客户端。

我的 MainActivity中有以下基本代码:

using Android.App;
using Android.OS;
using Android.Widget;
using Matrix;
using System.Threading.Tasks;

namespace XmppAndroid
{
    [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
    public class MainActivity : Activity
    {
        private ToastHandler handler;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            var button = FindViewById<Button>(Resource.Id.button);
            button.Click += delegate
            {
                Task task = new Task(Connect);
                task.Start();
            };

            handler = new ToastHandler(this);
        }

        async void Connect()
        {
            var msg = new Android.OS.Message();

            msg.Data.PutString("message", "Connecting...");
            handler.SendMessage(msg);

            var client = new XmppClient
            {
                Username = "username",
                Password = "123456",
                XmppDomain = "domain.com"
            };

            await client.ConnectAsync();

            msg.Data.PutString("message", "Connected!");
            handler.SendMessage(msg);
        }
    }
}

ToastHandler只是创建吐司的简单处理程序。我知道它确实有效,因为屏幕上出现消息“正在连接...”。但是,第二条消息没有出现。客户端似乎拒绝连接。

有什么想法要解决吗?

0 个答案:

没有答案