Search code examples
javaandroidapache-httpclient-4.xapache-httpcomponents

HttpGet, HttpClient, HttpResponse, HttpEntity, EntityUtils deprectated


i'm using android studio API 23 and i have these warnings deprecated warning

Here's my code

@Override
    protected Boolean doInBackground(String... urls) {
        String strNama[], strDeskripsi[], strFoto[], strMarker[], strLng[], strLat[];

        try {
            HttpGet httppost = new HttpGet(urls[0]);
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response = httpclient.execute(httppost);
            int status = response.getStatusLine().getStatusCode();
            if (status == 200) {
                HttpEntity entity = response.getEntity();
                String data = EntityUtils.toString(entity);
                JSONObject jsono = new JSONObject(data);
                JSONArray konten = jsono.getJSONArray("konten");
                strNama = new String[konten.length()];
                strDeskripsi = new String[konten.length()];
                strFoto = new String[konten.length()];
                strMarker = new String[konten.length()];
                strLat = new String[konten.length()];
                strLng = new String[konten.length()];
                for (int i = 0; i < konten.length(); i++) {
                    JSONObject object = konten.getJSONObject(i);
                    strNama[i] = object.getString("nama");
                    strDeskripsi[i] = object.getString("deskripsi");
                    strFoto[i] = object.getString("foto");
                    strMarker[i] = object.getString("marker");
                    strLat[i] = object.getString("lat");
                    strLng[i] = object.getString("lng");
                    Actors actor = new Actors();
                    actor.setName(strNama[i]);
                    actor.setDescription(strDeskripsi[i]);
                    actor.setImage(strFoto[i]);
                    actor.setMarker(strMarker[i]);
                    actor.setLat(strLat[i]);
                    actor.setLng(strLng[i]);
                    actorsList.add(actor);
                }
                return true;
            }

        } catch (ParseException e1) {
            e1.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return false;
    }

And here's in module

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "com.krb.navigasi.petakebunrayabogor"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

It runs fine in android 5.0 but how can i solve these warnings? I hope there's someone can help me to fix my code above. Any help will be greatly appreciated.

Thanks in advance.


Solution

  • Just initialize this,and sync

    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.cli‌​ent:4.1.2'