0
我想从图库中显示图像WebView但有些东西不起作用。我的webview不想显示源代码如下:file://storage/sdcard0/Download/obrazek.jpg或file://system/media/Andy29WP.png。来自file://系统或文件的WebView图像源://存储
我的JavaScript桥:
private class MyJavaScriptInterface {
@SuppressWarnings("unused")
Context mContext;
@SuppressWarnings("unused")
private static final int SELECT_PICTURE = 1;
MyJavaScriptInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void imageChooser(final String id){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);
String imagePath = "";
String[] imgData = { MediaStore.Images.Media.DATA };
Cursor imgCursor = getContentResolver().query(m_image_uri, imgData, null, null, null);
if(imgCursor!=null) {
int index = imgCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
imgCursor.moveToFirst();
imagePath = imgCursor.getString(index);
}
else
imagePath = m_image_uri.getPath();
m_image_path = imagePath;
String test_image_path = "file:/" + m_image_path;
Log.i("url obrazka", "url obrazka" + test_image_path);
m_web_view.loadUrl("javascript:changeImage(\""+ id + "\",\"" + test_image_path +"\")");
}
}
我onActivityResult:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
// currImageURI is the global variable I'm using to hold the content:// URI of the image
m_image_uri = data.getData();
}
}
}
应用:
使用file:///存储......不是文件://存储.... – greenapps 2014-09-24 19:08:42
@greenapps感谢 – Volz 2014-09-24 19:18:52