1***@qq.com
1***@qq.com
  • 发布:2018-02-17 00:57
  • 更新:2018-02-17 00:57
  • 阅读:2422

webwiew 怎么加载Android本地的图片?(可得到路径,webview集成5plus img无法加载)

分类:HTML5+

*js***
function cameraResult(data) {
var img = document.createElement("img");
img.src = "file://"+data;
mui.toast(img.src);
mui("#bq-imglist")[0].appendChild(img);
}
// 拍照
function getImage() {
outSet('开始拍照:');
homeJava.openCamera();
}


***Android**
//js调用原生打开系统相机
@JavascriptInterface
public void openCamera() {
Toast.makeText(context, "openCamera", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
intent.addCategory(Intent.CATEGORY_DEFAULT);
ContentValues contentValues = new ContentValues(1);
String filePath = "/mnt/sdcard/wx45/cache/images/" + System.currentTimeMillis() + ".jpg";
SharedPreferences sp = context.getSharedPreferences("cache",Context.MODE_PRIVATE);
sp.edit().putString("imageCache",filePath).commit();
File mTmpFile = new File(filePath);
contentValues.put(MediaStore.Images.Media.DATA, mTmpFile.getAbsolutePath());
Uri uri = getContext().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
context.startActivityForResult(intent, 0);

}  

//接收系统相机返回信息
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mEntryProxy.onActivityExecute(this, ISysEventListener.SysEventType.onActivityResult, new Object[]{requestCode, resultCode, data});
switch (requestCode) {
case 0:
if ( resultCode == RESULT_OK) {
SharedPreferences sp = this.getSharedPreferences("cache", Context.MODE_PRIVATE);
String filePath = sp.getString("imageCache", "null");
Toast.makeText(this,requestCode+"",Toast.LENGTH_SHORT).show();
mBaseFragment.get(position).getWebview().loadUrl("javascript:cameraResult('"+filePath+"')");
}
break;
}
}


2018-02-17 00:57 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复