Android Allowing Main Thread I/O

An important aspect of Android App design is to never block the main UI thread with long running tasks. Doing so can result in an Application Not Responding (ANR) condition that can cause your App to be stopped. To prevent ANR conditions, always perform long running tasks such as I/O in background threads.

If you need to test I/O access from the main UI thread, you'll need to change the Thread Policy as shown below. Only do this for testing. In your production App, make sure you perform I/O operation in a background thread.

StrictMode.ThreadPolicy policy = 
    new  StrictMode.ThreadPolicy.Builder().permitAll().build(); 
StrictMode.setThreadPolicy(policy);