java.lang.RuntimeException: Unable to start service with intent has extras android.os.NetworkOnMainThreadException
<p>This is my first post here, and I hope I do it well...</p>

<p>I'm trying to edit an Open Source Updater (YAOS Updater), and when I try to connect, it gives me an error.</p>

<p>I'll try to explain the better I can.</p>

<p>I've added a value in the JSON used to list all the files. the new value of each file is urlArchivo, which contains the complete url of the file.</p>

<p>This is the part of the code:</p>

<pre><code>package org.yaosupdater.services;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.yaosupdater.R;

import android.annotation.TargetApi;
import android.app.DownloadManager;
import android.app.DownloadManager.Query;
import android.app.DownloadManager.Request;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

@TargetApi(16)
public class DownloadService extends Service{

private DownloadManager dm;
private String nombre;
private String archivo;
private String urlArchivo;
private String[] mirrors;
private long enqueue;

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onStart(Intent intent, int startid){
    super.onStart(intent, startid);
    dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    Bundle bundle = intent.getExtras();
    nombre = (String) bundle.get("nombre");
    Log.d("Dexafree", "Nombre: " +nombre);
    archivo = (String) bundle.get("archivo");
    Log.d("Dexafree", "Archivo: " +archivo);
    urlArchivo = (String) bundle.getString("urlArchivo");
    Log.d("Dexafree", "urlArchivo: " +urlArchivo);
    mirrors = (String[]) bundle.get("mirrors");
    URL url;
    int j = 0;
    boolean found = false;
    while((j &lt; mirrors.length)&amp;&amp;(!found)){
        try {
            url = new URL(urlArchivo);
            Log.d("Dexafree", "Intentando conectar a: " +urlArchivo);
            //url = new URL(urlArchivo);
            //Log.d("Dexafree", "Intentando conectar a: " +urlArchivo);
            URLConnection urlCon = url.openConnection();
            Log.d("Dexafree", "Conexion abierta a: " +urlCon);
            Log.d("Dexafree", "Debe ser igual a: " + urlArchivo);
            InputStreamReader is = new InputStreamReader(urlCon.getInputStream());
            found = true;
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            Log.d("MIUIEsUpdater", "El archivo " +urlArchivo +" no se encontró.");
            found = false;
        }
        j++;
    }   
    j--;
</code></pre>

<p>The variable urlArchivo, in the logcat, gets the right URL, I mean, the </p>

<pre><code>    Log.d("Dexafree", "Intentando conectar a: " +urlArchivo);
</code></pre>

<p>Returns the correct complete url of the file, but it FC, showing the next logcat</p>

<pre><code>08-19 14:51:40.417: E/Trace(4134): error opening trace file: No such file or directory (2)
08-19 14:51:40.449: D/Dexafree(4134): Nombre: MODEM KF1
08-19 14:51:40.453: D/Dexafree(4134): Archivo: Modem_KF1.zip
08-19 14:51:40.453: D/Dexafree(4134): urlArchivo: http://content.wuala.com/contents/elitemovil/Galaxy_S/GT-I9000/carpetaprueba/Modem_KF1.zip
08-19 14:51:40.453: D/Dexafree(4134): Intentando conectar a: http://content.wuala.com/contents/elitemovil/Galaxy_S/GT-I9000/carpetaprueba/Modem_KF1.zip
08-19 14:51:40.453: D/Dexafree(4134): Conexion abierta a: libcore.net.http.HttpURLConnectionImpl:http://content.wuala.com/contents/elitemovil/Galaxy_S/GT-I9000/carpetaprueba/Modem_KF1.zip
08-19 14:51:40.453: D/Dexafree(4134): Debe ser igual a: http://content.wuala.com/contents/elitemovil/Galaxy_S/GT-I9000/carpetaprueba/Modem_KF1.zip
08-19 14:51:40.457: D/AndroidRuntime(4134): Shutting down VM
08-19 14:51:40.457: W/dalvikvm(4134): threadid=1: thread exiting with uncaught exception (group=0x40edb300)
08-19 14:51:40.500: E/AndroidRuntime(4134): FATAL EXCEPTION: main
08-19 14:51:40.500: E/AndroidRuntime(4134): java.lang.RuntimeException: Unable to start service org.yaosupdater.services.DownloadService@416c0c38 with Intent { cmp=org.yaosupdater/.services.DownloadService (has extras) }: android.os.NetworkOnMainThreadException
08-19 14:51:40.500: E/AndroidRuntime(4134):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2507)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at android.app.ActivityThread.access$1900(ActivityThread.java:130)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at android.os.Looper.loop(Looper.java:137)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at android.app.ActivityThread.main(ActivityThread.java:4745)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at java.lang.reflect.Method.invokeNative(Native Method)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at java.lang.reflect.Method.invoke(Method.java:511)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at dalvik.system.NativeStart.main(Native Method)
08-19 14:51:40.500: E/AndroidRuntime(4134): Caused by: android.os.NetworkOnMainThreadException
08-19 14:51:40.500: E/AndroidRuntime(4134):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at java.net.InetAddress.getAllByName(InetAddress.java:214)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:70)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:50)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at org.yaosupdater.services.DownloadService.onStart(DownloadService.java:73)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at android.app.Service.onStartCommand(Service.java:450)
08-19 14:51:40.500: E/AndroidRuntime(4134):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2490)
08-19 14:51:40.500: E/AndroidRuntime(4134):     ... 10 more
</code></pre>

<p>I hope I've posted all the information needed to solve this problem. If any more information is needed, please let me know!</p>
