Umesh

Untitled Document

Monday, 1 April 2013

android.os.NetworkOnMainThreadException or Unable to load Images From Twitter on android 4.0 Emulator or Device


Hello guys, after spending whole day, I got nice solution for my own  problem. Actualy I am feeding twitter data in my android application.  I am parsing user_name, created_at(means tweet time) and profile image url. When I parse these from twitter JSON, all data will shown in my listview properly. These is no any problem with my android 2.2,2.3.. emulator and device, but when I run this same code for my android 4.0 or up emulator and device , Image does not loads.


But finally I got my solution : Please fallow steps to resolve your problem..

Write below code into your Main Activity where your are showing listview just below

setContentView(R.layout.main_activity);

code:

if (android.os.Build.VERSION.SDK_INT > 9)
 {
     StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
     StrictMode.setThreadPolicy(policy);
 }

The above if condition is execute if your device api version is > 9 and if your device api version is less than 9 then your code is completely work without any error. Now my code works fine with all v ersion of devices properly.

And import below statement into your activity

import android.os.StrictMode

No comments:

Post a Comment