LuckSiege / LuckSiege/PictureSelector
OnResultCallbackListener 的 onResult 方法不会执行
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 13.6k
- Forks
- 3.1k
- PR merge metrics
- No merged PRs in 30d
Description
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 都有。
请问可能是什么原因?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the shown PictureSelector.create(...).forResult flow and the setSandboxFileEngine callback, then investigate why onUriToFileAsyncTransform runs without OnResultCallbackListener.onResult on Huawei and Honor devices running Android 12 or 14. Reproduce with the supplied Kotlin usage and targetSdkVersion/compileSdkVersion 30; done means identifying the callback failure and confirming a fix or documented cause.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100