恶魔微笑001 2016-05-11 07:38 采纳率: 0%
浏览 1262

android webview file事件响应 选择图片过程中退出的话 按钮点不了

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode==REQUEST_UPLOAD_FILE_CODE) {  
        if (null == mUploadFile) return;  
        Uri result = data == null || resultCode != -1 ? null  
                : data.getData();

// UriConvert(result);
mUploadFile.onReceiveValue(UriConvert(result));

mUploadFile = null;
}
else{
if (null == mUploadFile) return;
//显示到图库
File f = new File(imagePaths);
addImageGallery(f);
Uri result = cameraUri;
if(result!=null){
if(resultCode==-1){
mUploadFile.onReceiveValue(UriConvert(result));

mUploadFile = null;
}
}
}
}
//将低于4.4版本的URI转换为4.4以上版本能读的uri形式
public Uri UriConvert(Uri uri){
if (android.os.Build.VERSION.SDK_INT String filePath;
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getActivity().getContentResolver().query(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
filePath = cursor.getString(column_index);
return Uri.fromFile(new File(filePath));
}else{
return uri;
}
}
moreWebView.setWebChromeClient(new WebChromeClient(){
// For Android 3.0+
public void openFileChooser(ValueCallback uploadMsg, String acceptType) {

if (mUploadFile != null) return;
mUploadFile = uploadMsg;
selectImage();
// Intent i = new Intent(Intent.ACTION_GET_CONTENT);
// i.addCategory(Intent.CATEGORY_OPENABLE);
// i.setType("*/*");
// startActivityForResult( Intent.createChooser( i, "File Chooser" ), MainActivity.REQUEST_UPLOAD_FILE_CODE );
}
// For Android < 3.0
public void openFileChooser(ValueCallback uploadMsg) {
openFileChooser( uploadMsg, "" );
}
// For Android > 4.1.1
public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) {
openFileChooser(uploadMsg, acceptType);
}
});
//选择系统图库跟打开拍照
protected void selectImage() {
if (!checkSDcard())
return;
String[] selectPicTypeStr = { "拍照上传","图片或文件上传"};
new AlertDialog.Builder(getActivity())
.setItems(selectPicTypeStr,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
switch (which) {
// 相机拍摄
case 0:
openCarcme();
break;
//图库
case 1:
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
startActivityForResult( Intent.createChooser( i, "File Chooser" ), REQUEST_UPLOAD_FILE_CODE );
} else {
startActivityForResult( Intent.createChooser( i, "File Chooser" ), REQUEST_UPLOAD_FILE_CODE_SMALL );
};
break;
default:
break;
}
}
}).show();
}

  • 写回答

1条回答

  • 普通网友 2016-10-07 17:25
    关注

    生成api还有其他的吗,除了草料
    我想做一个名片二维码生成功能,图片说明
    上面图片是草料二维码生成的,但是草料的api还要提交申请上面的太麻烦了,我想有没有其他的api来做这个类似的功能。在线等,315895718 QQ,最好赋个demo

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog