NameValuePair is deprecated in API 22
Asked Answered
M

2

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

}
Melchor answered 7/4, 2015 at 5:6 Comment(1)
All of Apache Http is deprecated (it hasn't been updated in over 3 years) so the problem is slightly bigger than just NameValuePair.Yul
L
2

You can use contentValues for example

ContentValues values=new ContentValues();
values.put("username",name);
values.put("password",password);
Lamoreaux answered 30/10, 2015 at 8:44 Comment(0)
B
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.

Brinkema answered 7/4, 2015 at 5:24 Comment(3)
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.Melchor
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.Brinkema
MultipartEntity is 3rd party api so it can't be deprecatedBrinkema

© 2022 - 2024 — McMap. All rights reserved.