From be2c0c0984a305d81f4b2a562237e9d5e478c8cc Mon Sep 17 00:00:00 2001 From: Niko Strijbol Date: Sun, 23 Apr 2017 15:40:59 +0200 Subject: [PATCH] Catch crash on older Android versions --- .../be/ugent/zeus/hydra/ui/common/html/Utils.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/be/ugent/zeus/hydra/ui/common/html/Utils.java b/app/src/main/java/be/ugent/zeus/hydra/ui/common/html/Utils.java index 29171382d..43520d099 100644 --- a/app/src/main/java/be/ugent/zeus/hydra/ui/common/html/Utils.java +++ b/app/src/main/java/be/ugent/zeus/hydra/ui/common/html/Utils.java @@ -4,12 +4,15 @@ import android.text.Html; import android.text.SpannableString; import android.text.Spanned; +import android.util.Log; /** * @author Niko Strijbol */ public class Utils { + private static final String TAG = "HtmlUtils"; + /** * Helper with older version support. If the html is null, an empty Spannable will be returned. * @@ -25,8 +28,13 @@ public static Spanned fromHtml(String html, Html.ImageGetter getter) { } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { - //noinspection deprecation - return Html.fromHtml(html, getter, new HtmlTagHandler()); + try { + return Html.fromHtml(html, getter, new HtmlTagHandler()); + } catch (RuntimeException e) { + // Older versions crash sometimes, so try again without custom tags. + Log.e(TAG, "Error while reading html.", e); + return Html.fromHtml(html, getter, null); + } } else { return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY, getter, new HtmlTagHandler()); }