Hi SOB, thanks for replying.
Today I pushed all my files "Google.html", "test.jpg" and "ex.css" into assets folder and then tried to load into the WebView. It launches my HTML file but unable to load CSS/Images files into the webview. :( I tried to search forums but did not get any concrete solution. Any other clue? What I can try more. Anyways thanks for all your help. I am pasting mine code below:- _____________________________________________________________________________________ LocalFileBrowsing.java ---------------------------------------------------------------------------------- public class LocalFileBrowsing extends Activity { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); WebView webView = new WebView(this); setContentView(webView); InputStream is =null; byte[] byteArray = null; int read = -1; try { is = getAssets().open("Google.html"); byteArray = new byte[is.available()]; read = is.read(byteArray); System.out.println("Available: " + is.available()); System.out.println("Bytes read: " + read); } catch (IOException e2) { e2.printStackTrace(); } webView.loadData(new String(byteArray), "text/ html", "utf-8"); } } _____________________________________________________________________________________ Thanks, Ajeet Singh On Apr 16, 9:35 pm, Streets Of Boston <flyingdutc...@gmail.com> wrote: > This looks like a bug or limited functionality with WebView. > I know that it does work with http:// urls. > I know that it does work with HTML pages (and images, CSS files, etc) > from your application's 'assets' directory. > Maybe it won't work properly with HTML pages stored on your SDCARD or > you have to do something 'funky' to make it all work. > > Try to search in 'Android Developers' or 'Android Beginners' group to > see if someone else had similar problems. > > On Apr 16, 12:21 pm, Ajeet Singh <ajeet.invinci...@gmail.com> wrote: > > > > > Hi SOB, > > > Yes I have tried what all you said. But it also fail to load CSS/ > > Image which is specified in my HTML file. > > > I tried following things:- > > > 1- loadDataWithBaseURL(file.toURI().toString(), new String(arry), > > "text/html", "utf-8", "Error: 007"); > > 2- loadDataWithBaseURL(file.toURL().toString(), new String(arry), > > "text/html", "utf-8", "Error: 007"); > > 3- loadDataWithBaseURL("file:///sdcard/test.html", new String(arry), > > "text/html", "utf-8", "Error: 007"); > > 4- loadDataWithBaseURL("/sdcard/test.html", new String(arry), "text/ > > html", "utf-8", "Error: 007"); > > 5- loadDataWithBaseURL("/test.html", new String(arry), "text/html", > > "utf-8", "Error: 007"); > > > All above loads my test.html file very well. And I could see the HTML > > file. > > But They did not load CSS and images which which being specified in my > > test.html file. like > > > 1- For CCS we specify the path as > > <link rel="stylesheet" type="text/css" href="/sdcard/ex.css" /> > > > [Note: Here i also tried giving full paths like "file:///sdcard/ > > ex.css" ] > > > 2- For mages we specify path as > > <img src="/sdcard/testImage.jpg" width="150" height="113" /> > > [Note: Here i also tried giving full paths like "file:///sdcard/ > > ex.css" ] > > > Is there any other thing which I cam try? > > > Thanks for being so patient and listening to me. > > Ajeet Singh > > > On Apr 16, 6:59 pm, Streets Of Boston <flyingdutc...@gmail.com> wrote: > > > > That's how i understood your problem. > > > > That's what a base-url is for (the first paramater of > > > loadDataWithBaseURL). > > > You have to set this correctly so that URLs inside your HTML-document > > > can be correctly resolved. > > > > I think that the base-url "file" is not good. For starters, it is not > > > a valid URL. > > > A base-url should be absolute, not relative. This means it should > > > start with a scheme ("file://" or "http://") and followed by a domain > > > ("/" or "someserver.com") and then a path ("", "/" or "/sdcard/test/", > > > etc.). That's what the 'toURL()' from my earlies post takes care of. > > > > Have you tried my suggestions from my earlier post? > > > > On Apr 16, 4:26 am, Ajeet Singh <ajeet.invinci...@gmail.com> wrote: > > > > > Hi Streets Of Boston / wes > > > > > Thanks for your reply. > > > > I think you misunderstood the problem which I mentioned above/or may > > > > be I have not mention it clearly. Sorry for that. > > > > > I have my local HTML file which I am able to open that HTML file. > > > > But the problem is that my HTML file is unable to open other files > > > > like CSS files and Images, which are being specified in the HTML > > > > content like > > > > 1- For CCS we specify the path as > > > > <link rel="stylesheet" type="text/css" href="/sdcard/ex.css" /> > > > > 2- For mages we specify path as > > > > <img src="/sdcard/testImage.jpg" width="150" height="113" /> > > > > > So the CSS does not gets applied and Images also does not open. :( > > > > > Hope this time I am able to clear myself. > > > > > Thanks for your all information. > > > > Ajeet Singh > > > > > On Apr 16, 12:47 am, Streets Of Boston <flyingdutc...@gmail.com> > > > > wrote: > > > > > > Have you tried this: > > > > > > public class LocalFileBrowsing extends Activity { > > > > > @Override > > > > > public void onCreate(Bundle icicle) { > > > > > super.onCreate(icicle); > > > > > WebView webView = new WebView(this); > > > > > setContentView(webView); > > > > > File file = new File("/sdcard/Google.html"); > > > > > if (!file.exists()) > > > > > return; > > > > > byte[] arry = new byte[(int) file.length()]; > > > > > try { > > > > > FileInputStream fin = new FileInputStream(file); > > > > > fin.read(arry); > > > > > fin.close(); > > > > > } catch (Exception e) { > > > > > e.printStackTrace(); > > > > > } > > > > > webView.loadDataWithBaseURL( file.getAbsolutePath() , new > > > > > String(arry), "text/ > > > > > html", "utf-8", "Error: 404 "); > > > > > } > > > > > > } > > > > > > ("file" replaced by file.getAbsolutePath()) > > > > > If this does not work, try file.getParent().getAbsolutePath() instead. > > > > > > And if either does not work, create a file Uri out of either file or > > > > > file.getParent() use that as your first parameter in > > > > > loadDataWithBaseURL: file.toURL().toString() or file.getParent().toURL > > > > > ().toString() > > > > > > On Apr 15, 1:50 am, Ajeet Singh <ajeet.invinci...@gmail.com> wrote: > > > > > > > Hi Mike, > > > > > > > thanks for your reply. > > > > > > I already tried giving full path. But unfortunately this also does > > > > > > not > > > > > > work at all. > > > > > > > Any help would be appreciated. > > > > > > > Thanks, > > > > > > Ajeet Singh > > > > > > > On Apr 14, 10:19 pm, Mike Kedl <mike.k...@gmail.com> wrote: > > > > > > > > I'm just guessing since I haven't tried this myself, but wouldn't > > > > > > > you > > > > > > > need to specify the path more completely in the cs statement? > > > > > > > Since you are reading the html in, the base is not really > > > > > > > specified, > > > > > > > try either /sdcard/test_files/ex.cssor > > > > > > > file:///sdcard/test_files/ex.css. > > > > > > > (this is assuming you can read html from the filesystem at all) > > > > > > > > On Tue, Apr 14, 2009 at 4:43 AM, Ajeet Singh > > > > > > > <ajeet.invinci...@gmail.com> wrote: > > > > > > > > > Hi all, > > > > > > > > > Problem:cssis not loaded of a HTML file [ i am using > > > > > > > > loadDataWithBaseURL("file", new String(arry), "text/html", > > > > > > > > "utf-8", " > > > > > > > > ") from class WebView ] > > > > > > > > > What I have done: > > > > > > > > 1- Pushed test.HTML file into /sdcard > > > > > > > > 2- Made test_files folder in /sdcard (it looks like /sdcard/ > > > > > > > > test_files) > > > > > > > > 3- In folder /sdcard/test_files/ i pushed mycssfile (ex.css) > > > > > > > > 4- I read the test.html file into byte array and passing to > > > > > > > > function > > > > > > > > loadDataWithBaseURL() in string format. > > > > > > > > > Its proper behavour that html file should be loaded withcss > > > > > > > > properties. > > > > > > > > Butcssdoesn't executes at all :( in this case. > > > > > > > > > Can anybody help me regarding this? > > > > > > > > Why thecssfile is not executing at all? Is there any other way > > > > > > > > where > > > > > > > > I can load my html file with propercssapplied on. > > > > > > > > > I am giving all my code below here? > > > > > > > > > ------------------------------------------------------------------------------------------------- > > > > > > > > ------------------------------------------------------------------------------------------------- > > > > > > > > test.html > > > > > > > > ------------------------------------------------------------------------------------------------- > > > > > > > > <html> > > > > > > > > <head> > > > > > > > > <link rel="stylesheet" type="text/css" href="test_files/ex.css" > > > > > > > > /> > > > > > > > > </head> > > > > > > > > <body> > > > > > > > > > <h1>This header is 36 pt</h1> <h2>This header is blue</h2> > > > > > > > > <p>This > > > > > > > > paragraph has a left margin of 50 pixels</p> > > > > > > > > > </body> > > > > > > > > </html> > > > > > > > > -------------------------------------------------------------------------------------------------- > > > > > > > > --------------------------------------------------------------------------------------------------- > > > > > > > > ex.css > > > > > > > > ------------------------------------------------------------------------------------------------- > > > > > > > > body {background-color: yellow} h1 {font-size: 36pt} h2 {color: > > > > > > > > blue} > > > > > > > > p {margin-left: 50px} > > > > > > > > > ------------------------------------------------------------------------------------------------- > > > > > > > > ------------------------------------------------------------------------------------------------- > > > > > > > > My java code > > > > > > > > ------------------------------------------------------------------------------------------------- > > > > > > > > package com.android.LocalFileBrowsing; > > > > > > > > > import java.io.File; > > > > > > > > import java.io.FileInputStream; > > > > > > > > > import android.app.Activity; > > > > > > > > import android.os.Bundle; > > > > > > > > import android.webkit.WebView; > > > > > > > > > public class LocalFileBrowsing extends Activity { > > > > > > > > �...@override > > > > > > > > public void onCreate(Bundle icicle) { > > > > > > > > super.onCreate(icicle); > > > > > > > > WebView webView = new WebView(this); > > > > > > > > setContentView(webView); > > > > > > > > File file = new File("/sdcard/Google.html"); > > > > > > > > if (!file.exists()) > > > > > > > > return; > > > > > > > > byte[] arry = new byte[(int) file.length()]; > > > > > > > > try { > > > > > > > > FileInputStream fin = new FileInputStream(file); > > > > > > > > fin.read(arry); > > > > > > > > fin.close(); > > > > > > > > } catch (Exception e) { > > > > > > > > > > ... > > read more » --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Discuss" group. To post to this group, send email to android-discuss@googlegroups.com To unsubscribe from this group, send email to android-discuss+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-discuss?hl=en -~----------~----~----~----~------~----~------~--~---