Reputation: 131
In my application i need to load images from several urls into a Gridview. The problem is that my urls contain arabic characters and images aren't downloaded. I tested my app with English url and it's working fine, but i have problem with arabic ones. I have tried this to decode url but it's not working:
String result = URLDecoder.decode(imageUrls.get(j), "UTF-8");
also tried this:
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
Snippet to download bitmap:
for(j=0; j<imageUrls.size(); j++){
try {
String result = URLDecoder.decode(imageUrls.get(j), "UTF-8");
URL url=new URL(result);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(input);
btarray.add(bitmap);
} catch (Exception ex) {
}
}
and have
imageview.setImageBitmap(btarray.get(position));
in ImageAdapter getView method.
urls are like this: http://www.dalass.com/1/ShowPage.php?View=252-%D9%86%D8%A7%D8%AE%D9%86-DALASS-%D8%AF%D8%A7%D9%84%D8%A7%D8%B3.jpg
somebody help please
Upvotes: 1
Views: 1929
Reputation: 126523
You must use Uri.encode(String)
//String result = URLDecoder.decode(imageUrls.get(j), "UTF-8");
String result = Uri.encode(imageUrls.get(j));
URL url = new URL(result);
Upvotes: 3
Reputation: 69
Uri uri = Uri.parse(url);
String encodeUriString = Uri.encode(uri.getLastPathSegment());
String uriString = uri.toString().replace(uri.getLastPathSegment(), encodeUriString);
Log.d(TAG, uriString);
Upvotes: 0