0

I wan't to show a animated gif file in the Android App. The gif comes from a php backend.

This is the way im doing the request with the android app.

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setReadTimeout(15000);
                connection.setConnectTimeout(15000);
                connection.setRequestMethod("POST");
                connection.setDoInput(true);
                connection.setDoOutput(true);
                connection.setRequestProperty("Connection", "close");
                connection.setRequestProperty("Access-Control-Allow-Origin", "*");
                connection.setRequestProperty("Access-Control-Allow-Methods", "POST, GET");
                connection.setRequestProperty("Access-Control-Allow-Headers", "Content-Type, Authorization");
                connection.setRequestProperty("Content-Type", "multipart/form-data; charset=UTF-8");
                connection.setRequestProperty("Connection", "close");
                OutputStream os = connection.getOutputStream();
                BufferedWriter writer = new BufferedWriter(
                        new OutputStreamWriter(os, "UTF-8"));
                writer.write(body);
                writer.flush();
                writer.close();
                InputStream inputStream = connection.getInputStream();
                listener.onResult(inputStream);

This is the way the php backend returns the gif file.

header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
                header("Cache-Control: public"); // needed for internet explorer
                header("Content-Type: " . mime_content_type($fileName));
                header("Content-Transfer-Encoding: Binary");
                header("Content-Length:" . filesize($attachment_location));
                header("Content-Disposition: attachment; " . $fileName);
                header('Content-Disposition: attachment; filename="' . $fileName . '"');
                readfile($attachment_location);

For showing the gif I use the library pl.droidsonroids.gif:android-gif-drawable:1.2.23

And I set the image like this.

Bitmap img = BitmapFactory.decodeStream(inputStream);
GifDrawable gif = new GifDrawable(inputStreamTOByte(inputStream));
ivProfileImage.setImageDrawable(gif);

When I run it, it throws "GifIOException: GifError 103: Data is not in GIF format"

I don't know which part is wrong.

EDIT: I tried set the InputStream directly to the GifDrawable Object. But this throws a IllegalArgumentException: InputStream does not support marking

0 Answers0