I'm developing a Multiplatform App in Xamarin and I'm not able to load https images from an api. If I perform a build in Windows Phone the images are normally loaded already in android, so I ask, how to fix?
See the images
Android:
UWP
I'musingthefollowingcodetogetthedatathroughapi:
Home.cs
namespaceAppNewsPlay.Views{publicpartialclassHome:TabbedPage{//privateUltimasNoticiasUltimasNoticias;List<UltimasNoticias>UNoticias;publicTabbedPageDetail{get;privateset;}publicHome(){UNoticias=newList<UltimasNoticias>();ObterUltimasNoticias();InitializeComponent();}privateasyncvoidObterUltimasNoticias(){//varjsonRequest=JsonConvert.SerializeObject(UNoticias);//varhttpContent=newStringContent(jsonRequest,Encoding.UTF8,"application/json");
var resp = string.Empty;
try
{
var uri = new HttpClient();
uri.BaseAddress = new Uri("http://api.newsplay.com.br");
var url = "/api/post/";
var result = await uri.GetAsync(url);
if (!result.IsSuccessStatusCode)
{
await DisplayAlert("Erro de Conexão", "Não foi possível obter as notícias do servidor, Tente novamente mais tarde!", "OK");
return;
}
resp = await result.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
await DisplayAlert("Erro de Conexão com o Servidor", ex.Message, "OK");
return;
}
// transformando o retorno em objeto através do json e deserealize e retornando em lista
var UNoticias = JsonConvert.DeserializeObject<List<UltimasNoticias>>(resp);
//Adicionando os itens ao ListView na Home.xaml
UnoticiasList.ItemsSource = UNoticias;
}
private async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
if(e.SelectedItem !=null)
{
var selection = e.SelectedItem as UltimasNoticias;
//DisplayAlert("Você Selecionou", selection.Post_title, "ok");
await Navigation.PushAsync(new PostView());
#region DisabledSelectionHighlighting
((ListView)sender).SelectedItem = null;
#endregion
}
}
Home.xaml
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AppNewsPlay.Views.Home"
Title=""
Icon="LogoMobile.png"
>
<TabbedPage.Children>
<ContentPage Title="Ultimas Notícias" Icon="">
<ContentPage.Content>
<StackLayout
Spacing="20">
<Label Text="Últimas Notícias"
FontSize="20"
FontAttributes="Bold"
VerticalTextAlignment="Center"
HorizontalOptions="Center"
/>
<ListView x:Name="UnoticiasList"
HasUnevenRows="True"
SeparatorColor="White"
SeparatorVisibility="Default"
ItemSelected="OnItemSelected"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout
Padding="20"
Orientation="Vertical"
>
<Image Source="{Binding Guid}"
WidthRequest="250"
HeightRequest="150"
VerticalOptions="Center"
/>
<Label x:Name="Post_title" Text="{ Binding Post_title }"
FontSize="16"
FontAttributes="Bold"
HorizontalTextAlignment="Center"
/>
<Label x:Name="Post_content" Text="{ Binding Post_content }"
FontSize="12"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
HeightRequest="70"
/>
<Label x:Name="Post_ad" Text="{Binding Post_ad}"
FontSize="11"
HorizontalTextAlignment="Center"
/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
<ContentPage Title="Xbox" Icon="">
<ContentPage.Content>
</ContentPage.Content>
</ContentPage>
<ContentPage Title="Playstation" Icon="">
<ContentPage.Content>
</ContentPage.Content>
</ContentPage>
</TabbedPage.Children>
</TabbedPage>