Below is my code,While I am trying to do httpconnect from my app and make an API call.I am getting android.os.NetworkOnMainThreadException.What Can I do to fix my code.
URL url = new URL("http://sampleurl.com");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(15000);
        conn.setConnectTimeout(15000);
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
        conn.addRequestProperty("X-APP-Token", "value");
        conn.setDoInput(true);
        conn.setDoOutput(true);
        System.out.println("wILL ESTABLISH CON");
        Log.i("Net", "length=" + conn.getContentLength());
        Log.i("Net", "contentType=" + conn.getContentType());
        Log.i("Net", "content=" + conn.getContent());
        conn.connect();
        int response = conn.getResponseCode();
        Toast.makeText(getApplicationContext(),"CODE" + conn.getResponseCode(),Toast.LENGTH_LONG).show();
        System.out.println("RESPONSE " + response);
        InputStream in = conn.getInputStream();
