I found these links that may help you:

http://groups.google.com/group/android-developers/browse_thread/thread/beae7de5e2500cb6/9891024d8ddfeefb

http://www.techjini.com/blog/2009/01/10/android-tip-1-contentprovider-accessing-local-file-system-from-webview-showing-image-in-webview-using-content/


On Apr 18, 3:11 am, Ajeet Singh <[email protected]> wrote:
> Thanks SOB for that code.
>
> I works when I put my all html, css and images files into assets
> folder and try to load with webView.loadUrl("file:///android_asset/
> Google.html") . All css and images loaded completely.
>
> However similarly when I tried putting all my files into sdcard. It
> does not work at all.
>
> Just few more Ques:-
> 1- Can I save HTML/CSS/Images into that assets folder dynamically at
> run time. [As far as I know that assets folder deas not have any
> phusicall existence in the Android FileSystem ]
>
> 2- If not above point, then How that behavoir can be simulated for
> sdcard/or any other physical directory.
>
> Anyways Thanks for all your help
> Ajeet
>
> On Apr 17, 7:04 pm, Streets Of Boston <[email protected]> wrote:
>
>
>
> > 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 toCSSand 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 thecssas a URI such as
>
> > > > <head>
> > > > <link rel=”stylesheet” type=”text/css”
> > > > href=”content://com.yournamespace.maps.LocalFileContentProvider/
> > > > asset_filename.css” />
> > > > </head>
>
> > > > to insert thecsscontent 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 -- 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to