Google doesn't support legacy apache library so in the original class APKEpansionPolicy
this method uses URLEncodedUtils
and NameValuePair
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;
}
Replace this method in this and any other class with this piece of code that is splitting the query and using Map
instead of NameValuePair
.
private Map<String, String> decodeExtras(String extras) {
Map<String, String> results = new HashMap<String, String>();
try {
URI rawExtras = new URI("?" + extras);
Map<String, String> extraList = splitQuery(new URL(rawExtras.toString()));
for (Map.Entry<String, String> entry : extraList.entrySet())
{
String name = entry.getKey();
int i = 0;
while (results.containsKey(name)) {
name = entry.getKey() + ++i;
}
results.put(name, entry.getValue());
}
} catch (URISyntaxException e) {
Log.w(TAG, "Invalid syntax error while decoding extras data from server.");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return results;
}
public static Map<String, String> splitQuery(URL url) throws UnsupportedEncodingException {
Map<String, String> query_pairs = new LinkedHashMap<String, String>();
String query = url.getQuery();
String[] pairs = query.split("&");
for (String pair : pairs) {
int idx = pair.indexOf("=");
query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
}
return query_pairs;
}