Code example for URLConnection

Methods: connect, getContent

0
        new AsyncTask<Void, Void, Void>() {
            @Override 
            protected Void doInBackground(Void... voids) {
                try { 
                    URLConnection c = url.openConnection();
                    c.connect();
                    c.getContent();
                } catch (IOException e) {
                    Log.e("ERROR", "ERROR", e);
                } 
                return null; 
            } 
 
            @Override 
            protected void onPostExecute(Void aVoid) {
                Toast toast = Toast.makeText(view.getContext(), "Kjøpt", 2000);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } 
        }.execute(null, null);
    }