2011-10-27 16 views
3

webView.loadDataWithBaseURL()メソッドをアプリケーションのプライベートファイルに使用する場合、BaseURLを設定する方法を知りたいと思います。私がアクセスするファイルは、context.openFileOutput(filepath, Context.MODE_PRIVATE)またはcontext.openFileInput(filepath)です。 そんなことができることを願っています。Android WebView BaseURLをアプリケーションのプライベートファイルに設定する方法

ありがとうございました。

答えて

2

これを試してみて、

mWebView.loadUrl("file:///data/data/<package_name>/files/example.html"); 

またはInputStreamとして

ファイルを開くには、文字列にその入力ストリームを変換してloaddataWithBaseURL

FileInputStream fIn = openFileInput ("your internal storage file name"); 

int len = 0, ch; 
StringBuffer source = new StringBuffer(); 
// read the file char by char 
while((ch = fin.read()) != -1)  
source.append((char)ch); 
fIn.close(); 

mWebView.loadDataWithBaseURL(null,source,"text/html","UTF-8","about:blank"); 
に渡します
関連する問題