2 u013182821 u013182821 于 2016.05.11 15:38 提问

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个回答

silehaixianghuirenj
silehaixianghuirenj   2016.10.08 01:25

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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!