I am unable to fetch image using
Bitmap bitmap = getBitmapFromURL("http://ift.tt/1Dm7y3w");
if(bitmap!=null)
imageView.setImageBitmap(bitmap);
else
Toast.makeText(getActivity(),"null it is",Toast.LENGTH_SHORT).show();
Where getBitmapFromURL is
public static Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
But when I use below everything works fine
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
But I have read there Strict mode in android 2.2 that this policy is not safe to use and not just this, it is also blocking my main UI for few seconds.
I want to know first, why I am unable to fetch facebook profile pic without using above policy and Is there any way that I can avoid above policy and may able to fetch my profile pic? Thanks in advance :)
Aucun commentaire:
Enregistrer un commentaire