Skip to content Skip to sidebar Skip to footer

Android Studio - Namevaluepair And Httpparams Is Deprecated

I am new to Android development and I am have some deprecated issues. In Android Studio, it is stating that the NameValuePair and HttpParams is deprecated. ArrayList

Solution 1:

Did you try to use ContentValues ?

From this snippet of code I am not sure if it would help you.

ContentValues values=new ContentValues();

  values.put("fname",user.fname);
  values.put("lname", user.lname);
  values.put("email",user.email);
  values.put("password",user.password);

Solution 2:

you can use contentvalues or hashmap based on your preference.

i have used Content values

ContentValuescontentValues=newContentValues();
contentValues.put("key1","value1");
contentValues.put("key2","value2");

and if the data that u are posting is form data then here`s how u can convert it form data

publicStringgetFormData(ContentValues contentValues) throws UnsupportedEncodingException {

    StringBuilder sb = newStringBuilder();
    boolean first = true;
    for (Map.Entry<String, Object> entry : contentValues.valueSet()) {
        if (first)
            first = false;
        else
            sb.append("&");

        sb.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
        sb.append("=");
        sb.append(URLEncoder.encode(entry.getValue().toString(), "UTF-8"));
    }
    return sb.toString();
}

Solution 3:

Please add the below dependencies for both NameValuePair & Httpclient to make this work.

dependencies{
      compile'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
}

Post a Comment for "Android Studio - Namevaluepair And Httpparams Is Deprecated"