I have an adapter that must take the address of the image from the class object and pass it to the Picasso method.

But the fact is that the picture has an address with Russian characters, or Russian characters are in the way of the address, so Picasso does not want to load it, as I understand it. What solutions can be used?

In the path of the address "http: //" also added, did not help. Other pictures loads (checked with a commented line)

URLDecoder and URLEncoder have already started using it, I thought it would work in another encoding, no, it did not work = (

GIF format seems to be supported by Picasso, so I don’t sin on the extension of the picture

public View getView(int position, View convertView, ViewGroup parent) { // LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); // 3 обязательные строки при создании Array адаптера View newView = vi.inflate(R.layout.item_news, parent, false); // (в Cursor адаптере метод bindview) TextView tv1 = (TextView) newView.findViewById(R.id.textListViewZagolovok); TextView tv2 = (TextView) newView.findViewById(R.id.textListViewOpisanie); ImageView imv = (ImageView) newView.findViewById(R.id.imageListViewNovosti); String url = abc.get(position).image; // String url = "https://i.ytimg.com/vi/-DRziE7lYsk/hqdefault.jpg"; Log.e("pic in adapter", url); tv1.setText(abc.get(position).title); tv2.setText(abc.get(position).content); try{ // вот здесь косячит Picasso.with(context).load(URLEncoder.encode(url)).placeholder(R.drawable.headeronmenu).error(R.drawable.krest).into(imv); Log.e("encode", "0 " + url); Log.e("encode", "1 " + URLEncoder.encode(url, "UTF-8")); Log.e("encode", "2 " + URLDecoder.decode(url, "UTF-8")); }catch (UnsupportedEncodingException e){ e.printStackTrace(); } if(position == abc.size()-4 && !flagDow){ flagDow = true; downNextPage.startDowNextPage(); } return newView; } 

Logs:

 03-24 10:42:55.525 21687-21687/ru.diitcenter.lakdistrict E/pic in adapter: gazikumuh.ru/images/2016/ЦиркХури.gif 03-24 10:42:55.640 21687-21687/ru.diitcenter.lakdistrict E/encode: 0 gazikumuh.ru/images/2016/ЦиркХури.gif 03-24 10:42:55.645 21687-21687/ru.diitcenter.lakdistrict E/encode: 1 gazikumuh.ru%2Fimages%2F2016%2F%D0%A6%D0%B8%D1%80%D0%BA%D0%A5%D1%83%D1%80%D0%B8.gif 03-24 10:42:55.645 21687-21687/ru.diitcenter.lakdistrict E/encode: 2 gazikumuh.ru/images/2016/ЦиркХури.gif 03-24 10:42:55.720 21687-21687/ru.diitcenter.lakdistrict E/pic in adapter: gazikumuh.ru/images/2016/КурклиКультура.gif 03-24 10:42:55.720 21687-21687/ru.diitcenter.lakdistrict E/encode: 0 gazikumuh.ru/images/2016/КурклиКультура.gif 03-24 10:42:55.725 21687-21687/ru.diitcenter.lakdistrict E/encode: 1 gazikumuh.ru%2Fimages%2F2016%2F%D0%9A%D1%83%D1%80%D0%BA%D0%BB%D0%B8%D0%9A%D1%83%D0%BB%D1%8C%D1%82%D1%83%D1%80%D0%B0.gif 03-24 10:42:55.725 21687-21687/ru.diitcenter.lakdistrict E/encode: 2 gazikumuh.ru/images/2016/КурклиКультура.gif 03-24 10:43:00.760 21687-21687/ru.diitcenter.lakdistrict E/111: AboutNewsActivity.url = gazikumuh.ru/images/2016/ЦиркХури.gif 

(Pictures in the browser open)

  • Try to encode only the Cyrillic name of the picture, not the entire URL - Vladyslav Matviienko
  • Try to add URL to http: //, that is, the full link should be like this gazikumuh.ru/images/2016/TsirkHuri.gif - Android Android
  • Yes, it will help if the encoding is only the Cyrillic name of the picture. But how do I know where Cyrillic characters can be. Different formats come, in some 100% there are Russian characters not in the name itself, but in the way. Here is one of the examples "gazikumuh.ru/images/Shtatnyy_rabotniki/Glava_MR_Ysup_Gamidovich_-_640p.jpg" Regarding adding http: // - this does not help, already checked - zayn1991

2 answers 2

Here it seems helped with conversion =) using URI

 Uri.encode(url); 

    Using the links below, did the method

    [ https://stackoverflow.com/questions/9366742/android-regular-expression-return-matched-string ]

    [ http://www.javaportal.ru/java/articles/regexp.html ]

     public String convertUrl(String url){ Pattern p = Pattern.compile("[А-я]+_+[А-я]+_[А-я]+|[А-я]+_+[А-я]+|[А-я]+-+[А-я]+-+[А-я]+|[А-я]+-+[А-я]+|[А-я]+[0-9]+[А-я]+|[0-9]+[А-я]+|[А-я]+"); Matcher m = p.matcher(url); if(m.find()) { Log.e("regular", m.group(0)); String s = m.group(0); try { Log.e("regula2", URLEncoder.encode(s, "UTF-8")); return url.replace(s, URLEncoder.encode(s, "UTF-8")); } catch (UnsupportedEncodingException e) { } } return url; } 

    It translates titles with characters like

    http://gazikumuh.ru/images/2016/Прием_граждан_в.jpg http://gazikumuh.ru/images/2016/Прием_граждан.jpg http://gazikumuh.ru/images/2016/первый-второй-третий.jpg http://gazikumuh.ru/images/2016/первый-второй.jpg http://gazikumuh.ru/images/2016/первый0886796второй.jpg http://gazikumuh.ru/images/2016/первый-второй.jpg http://gazikumuh.ru/images/2016/0886796текст.gif http://gazikumuh.ru/images/2016/текст.gif

    Where "[А-я]" is 1 Russian symbol, "+" is a property of the set

    "[А-я] +" set of Russian characters

    "[AI] + _ + [AZ] +" is the word_word or the word ______ word

    My conditions are separated by the symbol "|" and if the 1st condition is not fulfilled, there will be a transition to the second condition and so on.

    Thanks to the people who left comments, I used their advice.