The code below works for me:
Check by using the image http url.
URL url = new URL(path);
URLConnection conn = url.openConnection();
InputStream inputStream = conn.getInputStream();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
inputStream.close();
byte[] bytes = outStream.toByteArray();
Movie gif = Movie.decodeByteArray(bytes, 0, bytes.length);
//If the result is true, its a animated GIF
if (gif != null) {
return true;
} else {
return false;
}
Or check by select file from gallery:
try {
//filePath is a String converted from a selected image's URI
File file = new File(filePath);
FileInputStream fileInputStream = new FileInputStream(file);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fileInputStream.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
fileInputStream.close();
byte[] bytes = outStream.toByteArray();
Movie gif = Movie.decodeByteArray(bytes, 0, bytes.length);
//If the result is true, its a animated GIF
if (gif != null) {
type = "Animated";
Log.d("Test", "Animated: " + type);
} else {
type = "notAnimated";
Log.d("Test", "Animated: " + type);
}
} catch (IOException ie) {
ie.printStackTrace();
}