java - Saving a URL to internal storage -
so title misleading. i've put url in drawable.
public drawable getdrawablefromurl(string url) { try { inputstream = (inputstream) new url(url).getcontent(); drawable d = drawable.createfromstream(is, "src name"); return d; } catch (exception e) { return null; } }
i had has bitmap kept getting nullpointers , android.os.networkonmainthreadexception
, i've managed fix, nullpointer comes around again. i'm stuck on how save internal, because can save sd fine.
thanks
try this
public class downloadimage extends asynctask<string, void, bitmap> { protected bitmap doinbackground(string... urls) { string urldisplay = urls[0]; bitmap micon11 = null; try { inputstream in = new java.net.url(urldisplay).openstream(); micon11 = bitmapfactory.decodestream(in); } catch (exception e) { log.d("error", e.getstacktrace().tostring()); } return micon11; } protected void onpostexecute(bitmap result) { // save bitmap here } }
to call asynctask
use below code
new downloadimage().execute(url);
Comments
Post a Comment