Can we display the xls file from the device store in my application?
I have currently created an android app.
In this application, I am successfully displaying an XLS file thanks to the google doc viewer and passing the file to the following urls:
WebView mWebView=new WebView(MyActivity.this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl("https://docs.google.com/gview?embedded=true&url="+LinkTo);
setContentView(mWebView);
So now I need to display the same XLS file that I saved to my device store, not the url this time, but directly from the store.
I have found many tips to do this with a file link in the url, but not with my file already on my device.
So, before I start, I would like to know if this is possible?
I have seen this method myWebView.loadData( );
Can I use it for my problem?
Can I use docs.google.com/gview with an internal file?
EDIT
I am trying to find a solution Der Gol ... lum
This is my code:
WebView wv = (WebView)findViewById(R.id.fileWebView);
wv.getSettings().setJavaScriptEnabled(true);
String root = Environment.getExternalStorageDirectory().toString();
String my_path = root + "/excel_files/";
wv.loadUrl("file://" + my_path + excelFile.getName());
wv.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
But webview displays blank page
source to share
Assuming your file is static and immutable , you can put the file in your folder assets
and use
mWebView.loadUrl("file:///android_asset/your_file");
to load into your WebView.
I am using this technique to display help (HTML files).
You can also use sub-folders under the assets
(in my case I use the URL-address, for example "file:///android_asset/help/help_" + language + ".htm"
),
because my file is in assets/help/
.
source to share