5***@qq.com
5***@qq.com
  • 发布:2024-10-12 10:18
  • 更新:2024-11-16 13:56
  • 阅读:93

uniappx 调用原生文件选择器

分类:uni-app x
UTSAndroid.onAppActivityResult((requestCode : Int, resultCode : Int, data ?: Intent) => {  
                if (requestCode == 1001) {  
                    let uri = data?.getData();  
                    if (uri != null) {  
                        const projection : Array<string> = ["_data"] as Array<string>;  
                        const context = UTSAndroid.getAppContext() as Context;  
                        if (context != null) {  
                            const resolver = context.getContentResolver();  
                            let tmp : Array<string> = [];  
// 下面这行代码报错了。第一个null值  
                            const cursor = resolver.query(uri, projection, null, null, null)  
                            if (cursor != null && cursor.moveToFirst()) {  
                                const cursorIndex = cursor.getColumnIndexOrThrow("_data");  
                            }  
                        }  

                        console.log(uri.getAuthority());  
                    }  
                    console.log(data?.getData());  
                    console.log(data?.getClipData())  
                }  
            });

控制台报错:

10:13:22.761 [plugin:uni:app-uts] 编译失败  
10:13:22.761 ‌error: 类型不匹配: 推断类型是UTSArray<String>,但预期的是Array<(out) String!>?(可为空的Array<(out) String!>)。‌  
10:13:22.761 at docs/docList.uvue:53:42
2024-10-12 10:18 负责人:无 分享
已邀请:
阿布朱朱

阿布朱朱

你好,解决了吗?

要回复问题请先登录注册