• Post Reply Bookmark Topic Watch Topic
  • New Topic

Android Socket-load Asset's CSS From HTML Header  RSS feed

Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating an application which accesses Asset's Folder's HTML Page.The HTML File as below,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<link href="css/index.css" rel="stylesheet" type="text/css" />
<h3> A White Header </h3>
<p> This paragraph has a blue font.
The background color of this page is gray because
we changed it with CSS!

and the index.css file is,

body{ background-color: gray;}
p { color: blue; }
h3{ color: white; }

I am reading the HTML file from Android and writing to socket outputstream like,

try {
InputStream localInputStream = this.context.getAssets().open("sendSMS.html");
PrintStream localPrintStream = new PrintStream(this.socket.getOutputStream(), true);
byte[] arrayOfByte = new byte[8192];
localPrintStream.println("HTTP/1.0 200 OK");
localPrintStream.println("Content-Type:text/html;charset=" + "UTF-8");
if (localInputStream.read(arrayOfByte) != -1)
String str = new String(arrayOfByte).trim();

} catch (IOException e) {
// TODO Auto-generated catch block
the expected Page output is,

but the received output is,

It seems like Once the response is written the HTML Page couldnt locate the local css file i specified.

So is there anyway i can read the css file specified in HTML Page and write it back to the outpustream?

I think i can do this with reading Page header but i dont know how to implement. Would be very grateful if someone could help me with this.Thanks
Posts: 42975
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So there is some process at the other end of that stream that somehow interprets HTML data? Does that process (please describe it in detail) know how to request and then use external CSS files? Is the Android app acting as a web server of some kind? If so, then it should not have problems serving files using appropriate URLs. If it is not a fill web server, then you might be better off embedding the CSS in the HTML.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!