6

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);
    }

}
Apsaliya
  • 136
  • 3
  • 10
  • All of Apache Http is deprecated (it hasn't been updated in over 3 years) so the problem is slightly bigger than just `NameValuePair`. – ianhanniballake Apr 07 '15 at 05:15

2 Answers2

2

You can use contentValues for example

ContentValues values=new ContentValues();
values.put("username",name);
values.put("password",password);
Rahul M Mohan
  • 293
  • 1
  • 3
  • 12
1

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.

Sahil Garg
  • 263
  • 1
  • 20
  • Looking at your code, I guess it works only for (String,String) argument. is it? If so, then please look at my code. I want to override it for (String,Double) arguments. Hope you get my problem. – Apsaliya Apr 07 '15 at 05:51
  • I just give you an example with string. You can add any type of value with this. I use this code to send data to my webservice, where name is the variable name in the service. – Sahil Garg Apr 07 '15 at 07:11
  • MultipartEntity is 3rd party api so it can't be deprecated – Sahil Garg Apr 07 '15 at 10:49