-
public class findModule extends WXModule {
/**
* 打开本地文件器
*/
JSCallback callback;@JSMethod(uiThread = true)
public void openPdf(final JSCallback callback) {
openFileSelector();
findModule.this.callback = callback;
}public void openFileSelector() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
// intent.setType("application/pdf");
intent.addCategory(Intent.CATEGORY_OPENABLE);
((Activity) (mWXSDKInstance.getContext())).startActivityForResult(intent, 0);
}@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0 && resultCode == Activity.RESULT_OK) {
Uri url = data.getData();
// String[] filePathColumns = {MediaStore.Images.Media.DATA};
// Cursor c = mWXSDKInstance.getContext().getContentResolver().query(url, null, null, null, null);
// c.moveToFirst();
// System.out.println(c );
// String v_file = c.getString(0);// 图片文件路径
// String v_path = c.getString(1);
// String v_size = c.getString(2); // 图片大小
// String v_name = c.getString(3); // 图片文件名
// String v_other = c.getString(4); // 图片文件名
// String picturePath = c.getString(columnIndex);
// c.close();
// 红色部分 这里是安卓系统4.4之前 uri 转 文件路径的老方法
// -------------------------- 这里很重要 -------------------------------------
String v_path = getPathByUri4kitkat(mWXSDKInstance.getContext(),url);
// -------------------------- 这里很重要 -------------------------------------
// getPathByUri4kitkat 这个方法 适合4.4 系统后 uri 转file路径System.out.println(v_path );
onResult(v_path);
}
}
// -------------------------- 结果回调 ------------
weex android 选择文件 拍照 获得uri 并转为文件真实路径 转base64码 回传weex
最新推荐文章于 2023-06-12 10:17:36 发布