url.openStream() not working on android
<p>Java code should download source code from facebook graph api, but is not working. Code output is <code>htmlCode = ""</code> 
This is java code:</p>

<pre><code>package cz.apps;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.*;
import java.net.URL;

public class MainActivity extends AppCompatActivity {

    public String htmlCode = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ziskatdata();
    }

    public void ziskatdata(){
        try {
            URL url = new URL("https://graph.facebook.com/v2.8/****/events?access_token=****");
           BufferedInputStream bis = new BufferedInputStream(url.openStream());
           byte[] buffer = new byte[1024];
           StringBuilder sb = new StringBuilder();
           int bytesRead = 0;
           while((bytesRead = bis.read(buffer)) &gt; 0) {
               String text = new String(buffer, 0, bytesRead);
               sb.append(text);
           }
           bis.close();

         htmlCode = sb.toString();
        } catch (Exception e) {
            //Data se nestáhla
        }

        if (htmlCode.equals("")){
            //Nezdařilo se vypsat události
        } else {
            try {
                JSONObject json = new JSONObject(htmlCode);
                JSONArray jarray = json.getJSONArray("data");
                for(int i = 0; i &lt; jarray.length(); i++){
                    JSONObject udalosti = jarray.getJSONObject(i);
                    String popis = udalosti.getString("description");
                    String konec = udalosti.getString("end_time");
                    String zacatek = udalosti.getString("start_time");
                    String jmeno = udalosti.getString("name");

                    JSONObject lokace = udalosti.getJSONObject("place").getJSONObject("location");
                    String mesto = lokace.getString("city");
                    String zeme = lokace.getString("country");
                    String lat = lokace.getString("latitude");
                    String lon = lokace.getString("longitude");
                    final TextView textViewToChange = (TextView) findViewById(R.id.textprovypsani);
                    textViewToChange.setText(mesto);
                }
            } catch (JSONException e) {
                //Něco je špatně
            }
        }
    }
}
</code></pre>

<p>AndroidManifest:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cz.app" &gt;
    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;

    &lt;application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" &gt;
        &lt;activity android:name=".MainActivity" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;
&lt;/manifest&gt;
</code></pre>

<p><code>catch (Exception e) { Log.e("MYAPP", "exception", e); }</code> LogCat output:</p>

<pre><code>E/MYAPP   (21057): exception
E/MYAPP   (21057): android.os.NetworkOnMainThreadException
</code></pre>