Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnResultCallbackListener 的 onResult 方法不会执行 #2961

Open
kiss718867 opened this issue Dec 12, 2024 · 0 comments
Open

OnResultCallbackListener 的 onResult 方法不会执行 #2961

kiss718867 opened this issue Dec 12, 2024 · 0 comments

Comments

@kiss718867
Copy link

Current use version?

当前使用的版本是多少?

3.11.2

Will this problem occur in demo?

Demo能否复现这问题?

目前手里的设备无法稳定复现,但线上有用户反馈,查看埋点日志也能发现

Describe the problem or provide an error log?

描述问题或提供错误log?

private fun openGallery(activity: Activity, mediaType: String, returnCallback: HybridWebView.ReturnCallback?) {
    FEStatistics.recordStatistics("0", "打开相册", HashMap<String, String>().apply {
        put("mediaType", mediaType)
    }, "")
    val type: Int
    val params: Array<String>
    if (mediaType == "image") {
        type = SelectMimeType.ofImage()
        params = arrayOf(PictureMimeType.JPEG_Q, PictureMimeType.PNG_Q, "image/jpg")
    } else {
        type = SelectMimeType.ofVideo()
        params = arrayOf(PictureMimeType.MP4_Q)
    }
    PictureSelector.create(activity)
        .openGallery(type)
        .setImageEngine(GlideEngine.createGlideEngine())
        .setVideoPlayerEngine(MediaPlayerEngine())
        .setMaxSelectNum(1)
        .setMaxVideoSelectNum(1)
        .setQueryOnlyMimeType(*params)
        .setSandboxFileEngine { context, srcPath, mineType, callback ->
            var sandboxPath = ""
            if (callback != null) {
                sandboxPath = SandboxTransformUtils.copyPathToSandbox(context, srcPath, mineType)
                callback.onCallback(srcPath, sandboxPath)
                Log.e(TAG, "onUriToFileAsyncTransform# srcPath=$srcPath, sandboxPath=$sandboxPath")
            }
            FEStatistics.recordStatistics("0", "选择文件, onUriToFileAsyncTransform", HashMap<String, String>().apply {
                put("mineType", mineType)
                put("srcPath", srcPath)
                put("sandboxPath", sandboxPath)
                put("callback", callback.toString())
            }, "")
        }
        .forResult(object : OnResultCallbackListener<LocalMedia?> {
            override fun onResult(result: ArrayList<LocalMedia?>) {
                if (result.isNotEmpty()) {
                    val media = result[0]
                    Log.e(TAG, "onResult# ${media?.realPath ?: ""}")
                    val file = media?.realPath?.let { File(it) }
                    val exists = file?.exists() ?: false
                    FEStatistics.recordStatistics("0", "选择文件完成", HashMap<String, String>().apply {
                        put("fileName", media?.fileName ?: "")
                        put("filePath", media?.realPath ?: "")
                        put("exists", exists.toString())
                        put("fileSize", (file?.length() ?: 0).toString())
                    }, "")
                    copyVideo2PrivateFolder(media?.realPath ?: "", media?.fileName ?: "", returnCallback)
                } else {
                    returnCallback?.call(JSONObject().apply {
                        put("status", -1)
                    })
                    Log.e(TAG, "onResult# empty")
                    FEStatistics.recordStatistics("2", "选择文件,result empty", HashMap(), "")
                }
            }

            override fun onCancel() {
                Log.e(TAG, "onCancel#")
                returnCallback?.call(JSONObject().apply {
                    put("status", -1)
                })
                FEStatistics.recordStatistics("2", "选择文件,cancel", HashMap(), "")
            }
        })
}

用法如上所示,应用的 targetSdkVersion 和 compileSdkVersion 都是 30。
看日志 SandboxFileEngine 的 onUriToFileAsyncTransform 会执行,但是 OnResultCallbackListener 的 onResult 不执行。
有问题的设备主要是华为和荣耀,Android 12 和 14 都有。

请问可能是什么原因?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant