How to download image from url in xamarin android? -


i'm trying download image url. code:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent">     <edittext         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/edt_main_url"         android:hint="url"         android:text="http://xamarin.com/resources/design/home/devices.png" />     <button         android:text="download"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/btt_main_download" />     <progressbar         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/prb_main_progress"         android:visibility="gone" />     <imageview         android:layout_width="match_parent"         android:layout_height="match_parent"         android:id="@+id/img_main_image"         android:scaletype="centerinside" /> </linearlayout> 

my button download clicked

void mbttdownload_click(object sender, eventargs e)         {             mprbprogress.visibility = viewstates.visible;              var url = new uri(medturl.text);              webclient webclient = new webclient();             webclient.downloaddataasync(url);              webclient.downloaddatacompleted += webclient_downloaddatacompleted;         } 

when webclient complete download

void webclient_downloaddatacompleted(object sender, downloaddatacompletedeventargs e)         {             mprbprogress.visibility = viewstates.gone;              var bytes = e.result;              if(bytes != null && bytes.length > 0)             {                 var imagebitmap = bitmapfactory.decodebytearray(bytes, 0, bytes.length);                 mimgimage.setimagebitmap(imagebitmap);             }         } 

but e.result null. set permission internet in manifest. nothing change! how can fix this? thank you!

i recommend using urlimageviewhelper component: urlimageviewhelper pretty great.

tis old school way of doing it: check in github


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -