【问题标题】:Picasso failed to load image from url written in bangla毕加索无法从用孟加拉语写的 url 加载图像
【发布时间】:2019-02-04 04:09:30
【问题描述】:

我使用 Picasso 库从远程服务器加载图像。图片网址是用混合语言(孟加拉语/英语)编写的。在某些设备中,它可以像 Chrome 浏览器一样完美加载。但在我的华为设备(型号 TIT-AL00))中,它无法加载。显示的默认图像。我的代码是:

String subjectIconUrl = https://devallorshathistorage.blob.core.windows.net/subject/Image_Subject_2018-06-12-064043044_কৃষিশিক্ষা_Krishi Shikkha.png;

    Picasso.with(context)
            .load(subjectIconUrl)
            .placeholder(R.drawable.ic_default)
            .error(R.drawable.ic_default)
            // To fit image into imageView
            .fit()
            // To prevent fade animation
            .noFade()
            .into(holder.imageSubjectIcon);

【问题讨论】:

    标签: android image url imageview picasso


    【解决方案1】:

    您需要对网址进行编码

    Uri.encode(url,"UTF-8");
    

    并尝试加载

    例子

    String subjectIconUrl = https://xyz/subject/Image_Subject_2018-06-12-064043044_কৃষিশিক্ষা_Krishi Shikkha.png;
    String encoded_url = Uri.encode(subjectIconUrl); 
    
    Picasso.with(context)
                .load(encoded_url)
                .placeholder(R.drawable.ic_default)
                .error(R.drawable.ic_default)
                // To fit image into imageView
                .fit()
                // To prevent fade animation
                .noFade()
                .into(holder.imageSubjectIcon);
    

    参考:https://developer.android.com/reference/android/net/Uri#encode(java.lang.String)

    【讨论】:

    • 在对我的所有图像进行编码后(包括之前加载的英文文件名)无法加载。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多