Xamarin.Android无法从Android 10 Q中的Azure数据库中提取表 [英] Xamarin.Android Cannot pull table from Azure database in Android 10 Q

查看:94
本文介绍了Xamarin.Android无法从Android 10 Q中的Azure数据库中提取表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实读过这本书,因为缺乏对Netcore 2.1 the的支持

I did read that because lack of support for Netcore 2.1 the

myItemsList = await App.MobileServiceAndroid.GetTable<MyTable>().ToListAsync();

当前在Android上不起作用,并且有一种变通方法是在MobileServiceClient的构造函数中传递HttpClientHandler(),所以我做到了:

does not currently work on Android, and there is a workaround to pass an HttpClientHandler() in the constructor of the MobileServiceClient, and so I did like this:

public static MobileServiceClient MobileServiceAndroid =
            new MobileServiceClient(AppConstants.AZURE_PRODUCTION_WEB_API_URL, new HttpClientHandler());

但这还不完整,仍然无法正常工作,我到底要做什么才能使它正常工作,任何指导都值得赞赏.

But this is incomplete,its still not working, what exactly do I have to do to make this work, any guidance is much appreciated.

推荐答案

据我了解,您正在使用Forms/PCL项目,而其他解决方案正在其Android项目中实现此代码. 对您来说,一旦将using Xamarin.Android.Net;添加到类中,您就应该能够做到这一点:

From my understanding, you are using a Forms/PCL project whereas the other solution was implementing this code inside their Android project. For you, once you add using Xamarin.Android.Net; to the class, you should be able to just do this:

public static MobileServiceClient MobileServiceAndroid =
            new MobileServiceClient(AppConstants.AZURE_PRODUCTION_WEB_API_URL, new AndroidClientHandler());


很可能您在使用using语句时可能会遇到问题,因为您必须遵循


Most likely you might have issues getting that using statement, for that you will have to follow steps shown here, or customized for you in the following steps:

  1. 将Xamarin Forms项目添加到您的所有项目中.
  2. 在Core项目中创建接口ICustomClientHandler

using System;
using System.Net.Http;

namespace Test
{
    public interface ICustomClientHandler
    {
        HttpClientHandler GetHandler();
    }
}

  1. 然后在Droid项目中创建一个CustomClientHandler,这将是依赖项服务的Android部分,它将帮助您检索本机AndroidClientHandler
  1. Then create a CustomClientHandler in the Droid project, which will be the Android part of the dependency service that will help you retrieve the native AndroidClientHandler

using System.Net.Http;
using Xamarin.Android.Net;
using System.Runtime.CompilerServices;
using Xamarin.Forms;
using Test;
[assembly: Xamarin.Forms.Dependency(typeof(Test.Droid.CustomClientHandler))]
namespace Test.Droid
{
    public class CustomClientHandler : ICustomClientHandler
    {
        public HttpClientHandler GetHandler()
        {
            return new AndroidClientHandler();
        }
    }
}

  1. 也以类似的方式实施iOS版本,但它将改为return new HttpClientHandler();
  2. 最后,在您的Core项目中使用如下所示的代码:

var clientHandler = DependencyService.Get<ICustomClientHandler>().GetHandler();
public static MobileServiceClient MobileServiceAndroid =
            new MobileServiceClient(AppConstants.AZURE_PRODUCTION_WEB_API_URL, clientHandler);

这篇关于Xamarin.Android无法从Android 10 Q中的Azure数据库中提取表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆