Aldasa Aldasa - 1 year ago 2408
Android Question

Html.fromHtml deprecated in Android N

I am using

to view html in a

Spanned result = Html.fromHtml(mNews.getTitle());

is now deprecated in Android N+

What/How do I find the new way of doing this?

Answer Source

You have to add a version check and use the old method on Android M and below, on Android N and higher you should use the new method. If you don't add a version check your app will break on lower Android versions.

Spanned result;

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
    result = Html.fromHtml(mNews.getTitle(),Html.FROM_HTML_MODE_LEGACY);
} else {
    result = Html.fromHtml(mNews.getTitle());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download