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

*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;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值