0

我试图让用户从手机的图库中选择一张图片。然后使用 webview 显示图像。检索到的文件路径类似于“content://media/external/images/media/14”。当我查看其他问题时,似乎他们的文件路径通常以“file://”开头

当程序运行时,它会显示一长串随机字符。不知道出了什么问题,感谢您的帮助。谢谢你

编辑此问题已通过 Md Abdul Gafur 的链接解决。新的固定代码:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
    //message is the path of the file.

    setContentView(R.layout.activity_picture_large);

    WebView myWebView = (WebView) findViewById(R.id.webview); 
    myWebView.getSettings().setAllowFileAccess(true);
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.getSettings().setBuiltInZoomControls(true);
    String html = "<html><head></head><body><p>hello</p><img src=\"" + message + "\" alt=\"alternativo\" /></body></html>";
    myWebView.loadDataWithBaseURL("", html, "text/html", "utf-8", "");

}
4

0 回答 0