studio programacion móviles link hipervinculo hacer descripcion desarrollo curso como aplicaciones android python html webview

android - programacion - meta title html



No se puede mostrar la cadena HTML (3)

He modificado el código aquí:

public class test extends Activity { private WebView wv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); wv = (WebView) findViewById(R.id.wv); String s = "<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <title>Saulify</title> <!-- All the Favicons... --> <link rel="shortcut icon" href="/static/favicon/favicon.ico"> <link rel="apple-touch-icon" sizes="57x57" href="/static/favicon/apple-touch-icon-57x57.png"> <link rel="apple-touch-icon" sizes="114x114" href="/static/favicon/apple-touch-icon-114x114.png"> <link rel="apple-touch-icon" sizes="72x72" href="/static/favicon/apple-touch-icon-72x72.png"> <link rel="apple-touch-icon" sizes="144x144" href="/static/favicon/apple-touch-icon-144x144.png"> <link rel="apple-touch-icon" sizes="60x60" href="/static/favicon/apple-touch-icon-60x60.png"> <link rel="apple-touch-icon" sizes="120x120" href="/static/favicon/apple-touch-icon-120x120.png"> <link rel="apple-touch-icon" sizes="76x76" href="/static/favicon/apple-touch-icon-76x76.png"> <link rel="apple-touch-icon" sizes="152x152" href="/static/favicon/apple-touch-icon-152x152.png"> <link rel="apple-touch-icon" sizes="180x180" href="/static/favicon/apple-touch-icon-180x180.png"> <link rel="icon" type="image/png" href="/static/favicon/favicon-192x192.png" sizes="192x192"> <link rel="icon" type="image/png" href="/static/favicon/favicon-160x160.png" sizes="160x160"> <link rel="icon" type="image/png" href="/static/favicon/favicon-96x96.png" sizes="96x96"> <link rel="icon" type="image/png" href="/static/favicon/favicon-16x16.png" sizes="16x16"> <link rel="icon" type="image/png" href="/static/favicon/favicon-32x32.png" sizes="32x32"> <meta name="msapplication-TileColor" content="#da532c"> <meta name="msapplication-TileImage" content="/static/favicon/mstile-144x144.png"> <meta name="msapplication-config" content="/static/favicon/browserconfig.xml"> <!-- External CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <!-- External Fonts --> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> <link href='//fonts.googleapis.com/css?family=Open+Sans:300,600' rel='stylesheet' type='text/css'> <link href='//fonts.googleapis.com/css?family=Lora:400,700' rel='stylesheet' type='text/css'> <!--[if lt IE 9]> <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script> <![endif]--> <!-- Site CSS --> <link rel="stylesheet" type="text/css" href="/static/css/style.css"> <link rel="stylesheet" type="text/css" href="/static/css/glyphicon.css"> </head> <body> <div class="container article-page"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <h2><a href="http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html">Gov. Jerry Brown Says Ted Cruz Is 'Absolutely Unfit' To Run For Office Because Of Climate Change Views</a></h2> <h4>Sam Levine</h4> <div class="article"> <p>California Gov. Jerry Brown (D) said on Sunday that Texas Sen. Ted Cruz (R-Texas) is "absolutely unfit to be running for office" because of his position on climate change.</p> <p>"I just came back from New Hampshire, where there's snow and ice everywhere. My view on this is simple: Debates on this should follow science and should follow data, and many of the alarmists on global warming, they have a problem because the science doesn't back them up," Cruz <a href="https://www.youtube.com/watch?v=m0UJ_Sc0Udk">said</a> on "Late Night with Seth Meyers" last week.</p> <p>To back up his claim, Cruz cited satellite data that has shown a lack of significant warming over the last 17 years. But Cruz's reasoning <a href="http://www.politifact.com/truth-o-meter/statements/2015/mar/20 /ted-cruz/ted-cruzs-worlds-fire-not-last-17-years/">has been debunked by Politifact</a>, which has shown that scientists have ample evidence to believe that the climate will continue to warm.</p> <p>"What he said is absolutely false,” Brown said on <a href="http://www.nbcnews.com/meet-the-press/california-governor-ted-cruz- unfit-be-running-n328046">NBC's "Meet the Press."</a> He added that <a href="http://climate.nasa.gov/scientific-consensus/">over 90 percent</a> of scientists who study the climate agree that climate change is caused by human activity. "That man betokens such a level of ignorance and a direct falsification of existing scientific data. It's shocking, and I think that man has rendered himself absolutely unfit to be running for office," Brown said.</p> <p>Brown added that climate change has <a href="http://www.huffingtonpost.com/2015/03/06/california-drought-february- record_n_6820704.html?utm_hp_ref=california-drought">caused droughts in his state</a>, as well as severe cold and storms on the east coast.</p> <p>While Cruz may have seen snow and ice everywhere in New Hampshire, data shows that the country is actually experiencing a <a href="http://www.huffingtonpost.com/2015/02/19/cold-weather- winter_n_6713104.html">warmer than average</a> winter.</p> <p>Brown’s criticism of Cruz comes one day before the Texas senator is set to announce a <a href="http://www.huffingtonpost.com/2015/03/22 /ted-cruz-2016_n_6917824.html">presidential campaign</a>. </p> </div> <div class="original"> <a href="http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html">VIEW ORIGINAL</a> </div> </div> </div> </div> <script src="//code.jquery.com/jquery-latest.js"></script> <script src="/static/js/modal.js"></script> <script src="/static/js/bootbox.min.js"></script> <script src="/static/js/site.js"></script> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-56257533-1', 'auto'); ga('send', 'pageview'); </script> </body> </html>"; wv.loadData(stripHtml(s), "text/html", "UTF-8"); } public String stripHtml(String html) { return Html.fromHtml(html).toString(); }

}

Estoy luchando con mostrar la cadena HTML en Android WebView. En el lado del servidor, descargué una página web y escapé de caracteres y citas HTML (usé Python):

my_string = html.escape(my_string, True)

En el lado del cliente de Android: las cadenas no se escapan por:

myString = StringEscapeUtils.unescapeHtml4(myString) webview.loadData( myString, "text/html", "encoding");

Sin embargo, webview solo los muestra como cadenas literales. Aquí están los resultados:

Edición: agrego una cadena original devuelta desde el lado del servidor:

"& lt;! DOCTYPE html & gt; & lt; html lang = & quot; es & gt; & lt; head & gt; & lt; meta charset =" utf-8 & quot; & gt; & lt; meta http-equiv = & quot; X-UA-Compatible & quot; content = & quot; IE = edge & quot; & gt; & lt; meta name = & quot; viewport & quot; content = & quot; width = device-width, initial-scale = 1.0 & quot; & gt; & lt; meta name = & quot; description & quot; content = & quot ; & quot; & gt; & lt; title & gt; Saulify & lt; / title & gt; & lt;! - Todos los Favicons ... - & gt; & lt; link rel = & quot; icono de acceso directo & quot; href = & static; favicon / favicon. ico & quot; & gt; & lt; link rel = & quot; apple-touch-icon & size = & quot; 57x57 & gt; href = & quot; /static/favicon/apple-touch-icon-57x57.png" & gt; & lt; link rel = & quot "apple-touch-icon" tamaños = "114x114" href = "/ static / favicon/apple-touch-icon-114x114.png" & gt; & lt; link rel =" apple-touch-icon "& quot; ; 72x72 "href =" / static/favicon/apple-touch-icon-72x72.png & quot; & gt; & lt; link rel = "apple-touch-icon" tamaños = "quot; 144x144" href = & quot; / static / favicon / manzana -touch-icon-144x144.png & quot; & gt; & lt; link rel = & quot; apple-touch-icon & quot; tamaños = & quot; 60x60 & quot; href = & quot; /static/favicon/apple-touch-icon-60x60.png" & gt; & lt; link rel = & quot; apple-touch-icon & quot; tamaños = & quot; 120x120 & quot; href = & quot; /static/favicon/apple-touch-icon-120x120.png" & gt; & lt; link rel = & quot; apple-touch-icon & quot; tamaños = & quot; 76x76 & quot; href = & quot; /static/favicon/apple-touch-icon-76x76.png" & gt; & lt; link rel = & quot; apple-touch-icon & quot; tamaños = & quot; 152x152 & quot; href = & quot; /static/favicon/apple-touch-icon-152x152.png" & gt; & lt; link rel = & quot; apple-touch-icon & quot; tamaños = & quot; 180x180 & quot; href = & quot; /static/favicon/apple-touch-icon-180x180.png" & gt; & lt; link rel = & quot; icono & quot; type = & quot; image / png & quot; href = & quot; /static/favicon/favicon-192x192.png" tamaños = & quot; 192x192 & quot; & gt; & lt; link rel = & quot; icono & quot; type = & quot; image / png & quot; href = & quot; /static/favicon/favicon-160x160.png" tamaños = & quot; 160x160 & quot; & gt; & lt; link rel = & quot; icono & quot; type = & quot; image / png & quot; href = & quot; /static/favicon/favicon-96x96.png" tamaños = & quot; 96x96 & quot; & gt; & lt; link rel = & quot; icono & quot; type = & quot; image / png & quot; href = & quot; /static/favicon/favicon-16x16.png" tamaños = & quot; 16x16 & quot; & gt; & lt; link rel = & quot; icono & quot; type = & quot; image / png & quot; href = & quot; /static/favicon/favicon-32x32.png" tamaños = & quot; 32x32 & quot; & gt; & lt; nombre meta = & quot; msapplication-TileColor & quot; contenido = & quot; # da532c & quot; & gt; & lt; nombre meta = & quot; msapplication-TileImage & quot; contenido = & quot; /static/favicon/mstile-144x144.png" & gt; & lt; nombre meta = & quot; msapplication-config & quot; contenido = & quot; /static/favicon/browserconfig.xml" & gt; & lt;! - CSS externo - & gt; & lt; link rel = & quot; hoja de estilo & quot; href = & quot; https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"&gt ; & lt;! - Fuentes externas - & gt; & lt; link href = & quot; // maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel = & quot; hoja de estilo & quot; & gt; & lt; link href = & # x27; // fonts.googleapis.com/css?family=Open+Sans: 300,600' rel = & # x27; hoja de estilo & # x27; escribe = & # x27; texto / css & # x27; & gt; & lt; link href = & # x27; // fonts.googleapis.com/css?family=Lora:400,700' rel = & # x27; hoja de estilo & # x27; escribe = & # x27; texto / css & # x27; & gt; & lt;! - [si es IE 9] & gt; & lt; script src = & quot; // cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script> & lt; script src = & quot; // cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script> & lt;! [endif] - & gt; & lt;! - Sitio CSS - & gt; & lt; link rel = & quot; hoja de estilo & quot; escribe = & quot; texto / css & quot; href = & quot; /static/css/style.css" & gt; & lt; link rel = & quot; hoja de estilo & quot; escribe = & quot; texto / css & quot; href = & quot; /static/css/glyphicon.css" & gt; & lt; / head & gt; & lt; cuerpo & gt; & lt; div class = & quot; contenedor artículo-página & quot; & gt; & lt; div class = & quot; fila & quot; & gt; & lt; div class = & quot; col-md-8 col-md-offset-2 & quot; & gt; & lt; h2 & gt; & lt; a href = & quot; http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html">Gov . Jerry Brown dice que Ted Cruz Is & amp; # 39; Absolutamente no apto & amp; # 39; Para postularse a la oficina debido al cambio climático Vistas & lt; / a & gt; & lt; / h2 & gt; & lt; h4 & gt; Sam Levine & lt; / h4 & gt; & lt; div class = & quot; artículo & quot; & gt; & lt; p & gt; el gobernador de California, Jerry Brown (D), dijo el domingo que el senador de Texas Ted Cruz (R-Texas) es "absolutamente inadecuado para postularse para un cargo" debido a su posición sobre el cambio climático. & lt; / p & gt; & lt; p & gt; & quot; Acabo de regresar de New Hampshire, donde hay nieve y hielo por todas partes. Mi opinión sobre esto es simple: los debates sobre esto deberían seguir a la ciencia y deberían seguir a los datos, y muchos de los alarmistas sobre el calentamiento global tienen un problema porque la ciencia no & # x27; t los respalda, & quot; Cruz & lt; a href = & quot; https://www.youtube.com/watch?v=m0UJ_Sc0Udk">said</a&gt ; en & quot; Late Night with Seth Meyers & quot; la semana pasada. & lt; / p & gt; & lt; p & gt; Para respaldar su afirmación, Cruz citó datos satelitales que han mostrado una falta de calentamiento significativo en los últimos 17 años. Pero el razonamiento de Cruz & # x27; s & lt; a href = & quot; http://www.politifact.com/truth-o-meter/statements/2015/mar/20 / ted-cruz / ted-cruzs-worlds-fire-not-last-17-years / & quot; & gt; ha sido desmentido por Politifact & lt; / a & gt ;, que ha demostrado que los científicos tienen amplia evidencia para creer que el clima continuará calentándose. & lt; / p & gt; & lt; p & gt; & quot; Lo que dijo es absolutamente falso ", dijo Brown en & lt; a href = & quot; http://www.nbcnews.com/meet-the-press/california-governor-ted-cruz- unfit-be-running-n328046 & quot; & gt; NBC & # x27; s & quot; Meet the Press. & quot; & lt; / un & gt; Añadió que & lt; a href = & quot; http://climate.nasa.gov/scientific-consensus/">over ;> más del 90 por ciento & lt; / a & gt; Los científicos que estudian el clima están de acuerdo en que el cambio climático es causado por la actividad humana. "Ese hombre revela un nivel de ignorancia y una falsificación directa de los datos científicos existentes. Es impactante, y creo que el hombre se ha mostrado absolutamente incapaz de postularse para un cargo, & quot; Brown dijo. & Lt; / p & gt; & lt; p & gt; Brown agregó que el cambio climático tiene & lt; a href = & quot; http://www.huffingtonpost.com/2015/03/06/california-drought-february- record_n_6820704.html? utm_hp_ref = california-sequía & quot; & gt; causó sequías en su estado & lt; / a & gt ;, así como el frío severo y tormentas en la costa este. & lt; / p & gt; & lt; p & gt; Si bien Cruz puede haber visto nieve y hielo en todas partes de New Hampshire, los datos muestran que el país realmente está experimentando una & lt; a href = & quot; http://www.huffingtonpost.com/2015/02/19/cold-weather- winter_n_6713104.html & quot; & gt; más cálido que el promedio & lt; / a & gt; invierno. & lt; / p & gt; La crítica de & lt; p & gt; Brown a Cruz se produce un día antes de que el senador de Texas tenga previsto anunciar un & lt; a href = & quot; http://www.huffingtonpost.com/2015/03/22 /ted-cruz-2016_n_6917824.html">presidential campaign & lt; / a & gt ;. & lt; / p & gt; & lt; / div & gt; & lt; div class = & quot; original & quot; & gt; & lt; a href = & quot; http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html">VIEW ORIGINAL & lt; / a & gt; & lt; / div & gt; & lt; / div & gt; & lt; / div & gt; & lt; / div & gt; & lt; script src = & quot; // code.jquery.com/jquery-latest.js"></script> & lt; script src = & quot; /static/js/modal.js" & gt; & lt; / script & gt; & lt; script src = & quot; /static/js/bootbox.min.js" & gt; & lt; / script & gt; & lt; script src = & quot; /static/js/site.js" & gt; & lt; / script & gt; & lt; script & gt; (función (i, s, o, g, r, a, m) {i [& # x27; GoogleAnalyticsObject & # x27;] = r; i [r] = i [r] || function () {(i [ r] .q = i [r] .q || []). push (argumentos)}, i [r] .l = 1 * nueva Fecha (); a = s.createElement (o), m = s. getElementsByTagName (o) [0]; a.async = 1; a.src = g; m.parentNode.insertBefore (a, m)}) (ventana, documento, & # x27; script & # x27;, & # x27; //www.google-analytics.com/analytics.js&#x27 ;,'ga'); ga (& # x27; create & # x27 ;, & # x27; UA-56257533-1 & # x27 ;, & # x27; auto & # x27;); ga (& # x27; enviar & # x27 ;, & # x27; pageview & # x27;); & lt; / script & gt; & lt; / body & gt; & lt; / html & gt; "


Prueba este código,

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N){ yourtextview.setText(Html.fromHtml(yourstring,Html.FROM_HTML_MODE_LEGACY)); } else { yourtextview.setText(Html.fromHtml(yourstring)); }


Prueba esto:

wv = (WebView) findViewById(R.id.wv); String s = "You HTML string"; wv.loadData(stripHtml(s), "text/html", "UTF-8"); public String stripHtml(String html) { return Html.fromHtml(html).toString(); }