0

I use to get data AQuery, source encoding windows-1251 at the first show everything is fine, but after the data is retrieved from the cache, do not I get the correct encoding.

I do

String url = "http://example.com/";
long expire = 15 * 60 * 1000;
aq.ajax(url, String.class, expire, new AjaxCallback<String>() {

    @Override
    public void callback(String url, String html, AjaxStatus status) {

        Log.i("DATA",html);

    }

});

the manual says so

If custom encoding is needed, uses the encoding() method to fix the encoding.

Tried so too, but it did not work

byte[] b = html.getBytes(Charset.forName("cp1251"));

try {
    html = new String(b, "UTF-8");
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }

Maybe somebody faced with this problem prompt decision means AQuery or how encoding string to UTF-8 > CP1251

Dharman
  • 30,962
  • 25
  • 85
  • 135
cjp2600
  • 31
  • 1
  • 6
  • What do you mean with `at first show` ? Where is a cache? How do you save it to cache? How do you retrieve from cache? Where is "the second show" ? – greenapps Jun 25 '14 at 18:10
  • All caching mechanism is handled by the library [AQuery (Android Query)](https://code.google.com/p/android-query/) in the method .ajax() – cjp2600 Jun 25 '14 at 23:38
  • That does not solve the problem. Why dont you make more effort to explain? Ok then you did not save to cache yourself. Now how did you retrieve from cache? How is it possible that you have `html` before and after cache? – greenapps Jun 26 '14 at 06:47

1 Answers1

0

This works for me:

long expire = 15 * 60 * 1000;

AjaxCallback<String> cb = new AjaxCallback<String>();
cb.url(url).type(String.class).weakHandler(this, "DataResponse").fileCache(true).expire(expire).encoding("Cp1251");

cb.header("Referer", "http://code.google.com/p/android-query/");
cb.header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2");

aq.ajax(cb);
Dharman
  • 30,962
  • 25
  • 85
  • 135
cjp2600
  • 31
  • 1
  • 6