I been following online tutorials on this code. and will publish google play with android api 23 Marshmallow.
private Map<String, String> decodeExtras(String extras) {
Map<String, String> results = new HashMap<String, String>();
try {
URI rawExtras = new URI("?" + extras);
List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8");
for (NameValuePair item : extraList) {
String name = item.getName();
int i = 0;
while (results.containsKey(name)) {
name = item.getName() + ++i;
}
results.put(name, item.getValue());
}
} catch (URISyntaxException e) {
Log.w(TAG, "Invalid syntax error while decoding extras data from server.");
}
return results;
}
But NameValuePair and URLEncodedUtils have been deleted in api23 Marshmallow . How can I change this code?
Please help me.
Just use Retrofit
OR
Use HttpURLConnection
OR
Add this to your build.gradle
(but it is not suggested)
android {
useLibrary 'org.apache.http.legacy'
}
Use httpMime.jar send data to server database.
Download the.jar from here and paste it in your libs folder.
Usage:
MultipartEntity multi = new MultipartEntity();
multi.addPart("username", new StringBody("Kgandroid"));
multi.addPart("password", new StringBody("nopass"));
This is a perfect alternative for namevaluepairs.
For URLEncodedUtils:
Read this.
You will find:
This preview removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption.
So now we have to use HttpUrlConnection
A simple tutorial to use HttpUrlConnection will be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With