Android Detect The Image Is Png/jpg/etc Extension From The Web
I have to read the image from my website. However, the images uploaded by users in the server have variety extensions. jpg png etc. How I can modify the image_url code to detect th
Solution 1:
You just check your Image_url
ends with .png
or not by using .endsWith(....)
method of String
like
if(image_url.endsWith(".png")){
//your image ends with .png
}else if(image_url.endsWith(".jpg")){
//your image ends with .jpg
}
Solution 2:
You Can use String.endsWith
method to do so see this link for better understanding.
String image_url = "http://testing-123.com/upload/products/" + pid +".png";
if(image_url.endsWith("png"))
{
//do something
}
elseif(image_url.endsWith("jpg"))
{
//do something
}
elseif(image_url.endsWith("bmp"))
{
//do something
}
Hope it will help you.
Solution 3:
This is the best way, If you are selecting an image from device.
...
/*
* Get the file's content URI from the incoming Intent, then
* get the file's MIME type
*/
Uri returnUri = returnIntent.getData();
String mimeType = getContentResolver().getType(returnUri);
https://developer.android.com/training/secure-file-sharing/retrieve-info#java ...
Post a Comment for "Android Detect The Image Is Png/jpg/etc Extension From The Web"