fix(webview): 解决文件选择器MIME类型解析和通知ID空指针问题
- 修复了文件下载通知中notifId为空时的崩溃问题 - 为XWebViewJsBridge添加了额外的回调参数以支持消息处理 - 重构了resolvePickerMimeType函数的文档注释并优化了MIME类型解析逻辑 - 将文件选择器的MIME类型解析逻辑统一到resolvePickerMimeType函数中 - 改进了HTML accept类型的转换机制,更好地支持混合和未知MIME类型
这个提交包含在:
父节点
0ce2f21307
当前提交
d19b0ae8fc
@ -190,12 +190,15 @@ object FileSDK {
|
|||||||
.also { NotificationManagerCompat.from(context).notify(id, it.build()) }
|
.also { NotificationManagerCompat.from(context).notify(id, it.build()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val capturedNotifId = notifId
|
||||||
try {
|
try {
|
||||||
FileTransfer.downloadToFile(downloadUrl, target) { progress ->
|
FileTransfer.downloadToFile(downloadUrl, target) { progress ->
|
||||||
|
if (capturedNotifId != null) {
|
||||||
notifBuilder?.let { builder ->
|
notifBuilder?.let { builder ->
|
||||||
builder.setProgress(100, progress, false)
|
builder.setProgress(100, progress, false)
|
||||||
if (NotificationManagerCompat.from(context).areNotificationsEnabled()) {
|
if (NotificationManagerCompat.from(context).areNotificationsEnabled()) {
|
||||||
NotificationManagerCompat.from(context).notify(notifId!!, builder.build())
|
NotificationManagerCompat.from(context).notify(capturedNotifId, builder.build())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onProgress(progress)
|
onProgress(progress)
|
||||||
|
|||||||
@ -100,7 +100,7 @@ class XWebViewActivity : ComponentActivity() {
|
|||||||
config.userAgent?.let { settings.userAgentString = it }
|
config.userAgent?.let { settings.userAgentString = it }
|
||||||
|
|
||||||
addJavascriptInterface(
|
addJavascriptInterface(
|
||||||
XWebViewJsBridge(mainHandler) { config.onMessage },
|
XWebViewJsBridge(mainHandler, { config.onMessage }, { null }),
|
||||||
config.jsBridgeName,
|
config.jsBridgeName,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -155,9 +155,7 @@ class XWebViewActivity : ComponentActivity() {
|
|||||||
fileCameraPermissionLauncher.launch(Manifest.permission.CAMERA)
|
fileCameraPermissionLauncher.launch(Manifest.permission.CAMERA)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val mimeType = fileChooserParams.acceptTypes
|
pickContentLauncher.launch(resolvePickerMimeType(fileChooserParams.acceptTypes))
|
||||||
.firstOrNull { it.isNotBlank() } ?: "image/*"
|
|
||||||
pickContentLauncher.launch(mimeType)
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,11 +42,8 @@ import org.json.JSONObject
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
// Maps HTML accept types (MIME or dot-prefixed extensions) to a single MIME for ACTION_GET_CONTENT.
|
||||||
* Converts an array of HTML accept types (MIME types or dot-prefixed extensions like ".docx")
|
// Returns "*/*" when types are empty, mixed, or cannot be resolved.
|
||||||
* into a single MIME type string suitable for ACTION_GET_CONTENT.
|
|
||||||
* Falls back to "*\/*" when types are mixed, unknown, or empty.
|
|
||||||
*/
|
|
||||||
internal fun resolvePickerMimeType(acceptTypes: Array<String>): String {
|
internal fun resolvePickerMimeType(acceptTypes: Array<String>): String {
|
||||||
val nonBlank = acceptTypes.filter { it.isNotBlank() }
|
val nonBlank = acceptTypes.filter { it.isNotBlank() }
|
||||||
if (nonBlank.isEmpty()) return "*/*"
|
if (nonBlank.isEmpty()) return "*/*"
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户