NameValuePair is deprecated in API 22

7.4k Views Asked by At

Now that namevaluepair is deprecated in API 22. What can i do if i want to implement 'namevaluepair' interface. below is my code

package com.example.passpass;

import org.apache.http.NameValuePair;

public class DoubleNameValuePair implements NameValuePair{

 String name;

    double value;

    public DoubleNameValuePair(String name, double value) {
        this.name = name;
        this.value = value;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getValue() {
        return Double.toString(value);
    }

}
2

There are 2 best solutions below

3
Sahil Garg On

You can use httpmime.jar file instead of it, which will work better that NameValuePair. You can Download it from here, http://www.java2s.com/Code/JarDownload/httpmime/httpmime-4.3.jar.zip/

Here is the sample code to use httpmime,

MultipartEntity multi = new MultipartEntity();
    try {
        multi.addPart("name", new StringBody("Sahil"));
        multi.addPart("country", new StringBody("India"));
    }
    catch(Exception e){
        System.out.println(""+e);
    }

just add this jar to your project and then you can access MultipartEntity class.

0
Rahul M Mohan On

You can use contentValues for example

ContentValues values=new ContentValues();
values.put("username",name);
values.put("password",password);