我想从一个有布局的地方发送一些HTML
代码,我想获取 代码并在. 我的代码是:MainActivity
WebViewActivity
WebView
HTML
webview
HTML
<html><img alt=\"myImagenotshowing\" src=\"file://mnt/sdcard/HappyEnding.jpg\"></html>
我WebViewActivity
的是:
public class WebViewActivity extends Activity {
@SuppressWarnings("unused")
private static String TAG = "WebViewActivity";
private WebView webView;
public static final String MY_EXTRA = "fulltext";
Bundle extras;
String value;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
value = getIntent().getStringExtra(MY_EXTRA);// Here it gets HTML code that I want to display inwebview
Log.w(MY_EXTRA, "Data recieved is >> " + value);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.webview);
// Makes Progress bar Visible
getWindow().setFeatureInt(Window.FEATURE_PROGRESS,
Window.PROGRESS_VISIBILITY_ON);
webView = (WebView) findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadData(value, "text/html", null);
return true;
}
});
new GetData().execute(null, null, null);
}
private class GetData extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
webView.getSettings().setDomStorageEnabled(true);
}
@SuppressLint("SetJavaScriptEnabled")
@Override
protected Void doInBackground(Void... params) {
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(
false);
webView.getSettings().setSupportMultipleWindows(false);
webView.getSettings().setSupportZoom(false);
webView.getSettings().setRenderPriority(
WebSettings.RenderPriority.HIGH);
webView.getSettings().setSavePassword(false);
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setAppCacheMaxSize(200);
webView.getSettings().setDatabaseEnabled(true);
webView.clearCache(true);
// webView.clearHistory();
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
webView.loadData(value, "text/html", null);
}
}}
上面的代码不显示来自/mnt/sdcard/HappyEnding.jpg
. 怎么解决。。
CODE
这是我发送的代码MainActivity
:
String value2 = "<html><img alt=\"myImagenotshowing\" src=\"file://mnt/sdcard/HappyEnding.jpg\"></html>";
intent = new Intent(MainActivity.this, WebViewActivity.class);
intent.putExtra(MY_EXTRA, value2);
startActivity(intent);