// CODIGO ANTIGO QUE NAO ATUALIZA, MAS UTILIZA UTF-8.
Cache cache = AppController.getInstance().getRequestQueue().getCache();
if (cache.get(URL_FEED) != null) {
// fetch the data from cache
try {
String data = new String(cache.get(URL_FEED).data, "utf-8");
try {
parseJsonFeed(new JSONObject(data));
} catch (JSONException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
// making fresh volley request and getting json
JsonObjectRequest jsonReq = new JsonObjectRequest(Method.GET,
URL_FEED, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
VolleyLog.d(TAG, "Response: " + response.toString());
if (response != null) {
parseJsonFeed(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
}
});
// Adding request to volley request queue
AppController.getInstance().addToRequestQueue(jsonReq);
}
}
// CODIGO QUE ATUALIZA, MAS NAO UTILIZA UTF-8.
JsonObjectRequest jsonReq = new JsonObjectRequest ( Method . GET ,
URL_FEED , null , new Response . Listener < JSONObject >() {
Override
pública vazio onResponse ( JSONObject resposta ) {
VolleyLog . d ( TAG , "Resposta:" + resposta . toString ());
se ( resposta ! = NULL ) {
parseJsonFeed ( resposta );
}
}
}, nova resposta . ErrorListener ( ) {
Override
pública vazio onErrorResponse ( VolleyError erro ) {
VolleyLog . d ( TAG , "Erro:" + erro . getMessage ());
}
});