I Ajeet,
In one of my apps, I load an HTML page as follows:
webView.loadUrl("file:///android_asset/help/helpgube.html");
Below is a snippet from the helpgube.html:
<head>
<meta http-equiv="content-type" content="text/html;
charset=utf-8" />
<link type="text/css" rel="stylesheet" id="helpCSS" href="./
helpgubecss.css" />
</head>
And here a snippet from helpgubecss.css
body {
BACKGROUND-POSITION: 0px 0px;
BACKGROUND-IMAGE: url(../images/screen1_trans.png);
BACKGROUND-REPEAT: repeat-y;
BACKGROUND-COLOR: transparent
}
As you can see, all internal links to CSS and images are relative. My
code does not use loadDataWithBaseURL. However, i think the form of
the url may be the key: "file:///android_asset/"
On Apr 17, 8:53 am, Ajeet Singh <[email protected]> wrote:
> Hi Wes,
>
> I tried the way which you are saying. but could not make it working.
> It was giving "file not found" exception. Even mine HTML is not
> getting loaded. May be I am paasing the wrong URL to my
> "LocalFileContentProvider.java"
>
> Can you give some hint how it can be done. or Can you give some sample
> code how the URL is paases and send to our
> LocalFileContentProvider.java
>
> Anyways I am pasting my code here. Can you see what I am doing wrong
> here?
>
> Any ways thanks for all help.
>
> What I have done is:
> 1- I pushed Google.html / ex.css/ test.jpg file to asset folder
> ____________________________________________________________________
> LocalFileAccess.java
> ----------------------------------------
> public class LocalFileAccess extends Activity {
> @Override
> public void onCreate(Bundle icicle) {
> super.onCreate(icicle);
> WebView webView = new WebView(this);
> setContentView(webView);
>
> Uri uri = Uri.parse("content://
> com.android.LocalFileAccess/Google.html");
> try {
> is = getContentResolver().openInputStream(uri);
> byteArray = new byte[is.available()];
> read = is.read(byteArray);
> System.out.println("Available: " + is.available());
> System.out.println("Bytes read: " + read);
> } catch (FileNotFoundException e) {
> e.printStackTrace();
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> webView.loadData(new String(byteArray), "text/html", "utf-8");
> }}
>
> ____________________________________________________________________
> LocalFileContentProvider.java
> -----------------------------------------------
> public class LocalFileContentProvider extends ContentProvider {
>
> private static final String URI_PREFIX = "content://
> com.android.LocalFileAccess";
>
> public static String constructUri(String url) {
> Uri uri = Uri.parse(url);
> return uri.isAbsolute() ? url : URI_PREFIX + url;
> }
>
> @Override
> public ParcelFileDescriptor openFile(Uri uri, String mode) throws
> FileNotFoundException {
> //URI u =
> URI.create("file:///data/data/com.android.LocalFileAccess/
> Google.html");
> File file = new File(uri.getPath());
> ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file,
> ParcelFileDescriptor.MODE_READ_ONLY);
> return parcel;
> }
>
> // Rest of methods I override, but I did not pasted it
> here.}
>
> ____________________________________________________________________
> AndroidManifest.xml
> ----------------------------------------------
>
> <provider android:name="LocalFileContentProvider"
>
> android:authorities="com.android.LocalFileAccess"
>
> android:grantUriPermissions="true"
> />
> ____________________________________________
>
> Thanks,
> Ajeet Singh
>
> On Apr 17, 9:56 am, wescorp <[email protected]> wrote:
>
>
>
> > After creating a ContentProvider using the mentioned tutorial, in your
> > html code, refer to the css as a URI such as
>
> > <head>
> > <link rel=”stylesheet” type=”text/css”
> > href=”content://com.yournamespace.maps.LocalFileContentProvider/
> > asset_filename.css” />
> > </head>
>
> > to insert the css content into the WebView.
>
> > I use something similar for javascript.
>
> > Cheers,
> > Wes
>
> > On Apr 15, 1:23 pm, wescorp <[email protected]> wrote:
>
> > > There are several examples of content providers for different purposes
> > > around.
>
> > > Here is one I found useful.
>
> > >http://blog.tourizo.com/2009/02/how-to-display-local-file-in-android....
>
> > > Mark Murphy's book examples is also good for learning
> > > ContentProviders.
>
> > > Cheers,
> > > Wes- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Android Discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---