android - Character Encoding downloading text from a web page -


i trying text html page, can download correctly accents in spanish (á, é, í, ó, ú) , other special caracters ( ü ) being showed square ? mark inside.

once inputstreamreader use calls read function, text appears this, html page , database stores content fine.

is there anyway specify inputstreamreader character encoding should expecting? using utf8_general_ci in database, , showing php page obtains text.

thanks.

private string downloadtext (string url) {     int buffer_size = 2000;     inputstream in = null;     try     {         in = openhttpconnection(url);     }     catch (ioexception e)     {         return "";     }      inputstreamreader isr = new inputstreamreader(in);     int charread;     string str = "";     char[] inputbuffer = new char[buffer_size];     try     {         charread = isr.read(inputbuffer);         str = string.copyvalueof(inputbuffer,0,charread);         inputbuffer = null;         in.close();     }     catch(ioexception e)     {         return "";     }     return str; } 

try add header

header('content-type: text/html; charset=utf-8' ); 

and after connect db

// connect server , select database. $login = mysql_connect("www.yoursite.com","username","password")  or die (mysql_error()); mysql_select_db("yourdatabase", $login); 

add 2 lines

mysql_query("set names 'utf8'"); mysql_query('set character set utf8'); 

Comments