I'm trying to show GIF image by URL from JSON file. For that, I have function, which takes JSONObject and show image by Glide.
public class FragmentHandler extends Fragment implements View.OnClickListener {
private void showJsonContent(JSONObject jsonObject) throws JSONException {
if (jsonObject == null) return;
String gifLink = jsonObject.getString("gifURL");
String desc = jsonObject.getString("description");
captionTextView.setText(desc);
Glide.with(Objects.requireNonNull(getActivity())
.getApplicationContext())
.asGif()
.load(gifLink)
.listener(new RequestListener<GifDrawable>() {
@Override
public boolean onLoadFailed(GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
}).into(new ImageViewTarget<GifDrawable>(imageView) {
@Override
protected void setResource(GifDrawable resource) {
imageView.setImageDrawable(resource);
}
});
}
}
Progress Bar and ImageView in XML looks like that:
<ProgressBar
android:id="@+id/progress"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:visibility="visible" />
<ImageView
android:id="@+id/imageView"
android:layout_width="240dp"
android:layout_height="240dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:contentDescription="@string/gif_image" />
It works absolutely correct on Android 6 Pixel emulator (API 26), but with devices (physical and emulator) with a higher version, it doesn't show image. URL and JSON correct, because program prints message from another JSON field and I tried to debug it for the check.
I read really a lot of posts with a similar problem at StackOverflow and tried all suggestions, mostly concerning using asGif()
. But it doesn't help. Are there any ways to solve this problem?
UPDATE:
Here is example of URL to the GIF image:
http://static.devli.ru/public/images/gifs/201402/90400af2-91c1-4f31-bf5e-b2561b598d7c.gif
And my AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gifapp">
<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:fullBackupContent="@xml/my_backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>