david_ramezani
david_ramezani

Reputation: 63

Android Square Picasso not load persian character image url

I want to create web application by square picasso, but if image url contains persian characters (ا،ب،ج،ی، ...) Picasso not load image.

This url not working:

        Picasso.with(mContext).load("http://www.shutterstock.ir/thumbs/10006/74601661-گربه-چشم-ابی-ولاغر-سیامی-در-یک-پس-زمینه-،-وکتور-سفید.jpg")
    .placeholder(R.drawable.ic_launcher)
    .error(R.drawable.face_top_image).noFade().resize(100, 100)
    .into(imageView);    

This url work

        Picasso.with(mContext).load("http://www.shutterstock.ir/thumbs/10006/74601661-%DA%AF%D8%B1%D8%A8%D9%87-%DA%86%D8%B4%D9%85-%D8%A7%D8%A8%DB%8C-%D9%88%D9%84%D8%A7%D8%BA%D8%B1-%D8%B3%DB%8C%D8%A7%D9%85%DB%8C-%D8%AF%D8%B1-%DB%8C%DA%A9-%D9%BE%D8%B3-%D8%B2%D9%85%DB%8C%D9%86%D9%87-%D8%8C-%D9%88%DA%A9%D8%AA%D9%88%D8%B1-%D8%B3%D9%81%DB%8C%D8%AF.jpg")
    .placeholder(R.drawable.ic_launcher)
    .error(R.drawable.face_top_image).noFade().resize(100, 100)
    .into(imageView);    

Upvotes: 4

Views: 1539

Answers (3)

saeed hasankhan
saeed hasankhan

Reputation: 29

just use from this function

 public static String encodUrl(String url){
            String[] splitUrl = url.split("/");
            String imageName = splitUrl[splitUrl.length-1];//get name of file
            String mainUrl = url.replaceAll(imageName , "");//get url without file name bacause dont need to encode

            return (mainUrl + Uri.encode(imageName));
        }

Upvotes: 0

stevebot
stevebot

Reputation: 24005

You need to URI encode the URL.

See the docs

Uri.encode(url);

Or, if specifying certain allowed characters the following works:

private static final String ALLOWED_URI_CHARS = "@#&=*+-_.,:!?()/~'%";
String urlEncoded = Uri.encode(path, ALLOWED_URI_CHARS);

Upvotes: 11

Saeed Masoumi
Saeed Masoumi

Reputation: 8916

You need to encode your Url . So try this

URIUtil.encodeQuery(myUrl).

or also this one : http://developer.android.com/reference/java/net/URLEncoder.html

URLEncoder.encode(myUrl, "UTF-8");

Also there is an issue here

Upvotes: 1

Related Questions