提交 40496116 authored 作者: JarvanMo's avatar JarvanMo

fix bug when sharing image on Android

上级 928c4d5b
...@@ -123,7 +123,7 @@ internal interface FluwxShareHandler : CoroutineScope { ...@@ -123,7 +123,7 @@ internal interface FluwxShareHandler : CoroutineScope {
private fun shareImage(call: MethodCall, result: MethodChannel.Result) { private fun shareImage(call: MethodCall, result: MethodChannel.Result) {
launch { launch {
val map: Map<String, Any> = call.argument("source") ?: mapOf() val map: Map<String, Any> = call.argument("source") ?: mapOf()
val sourceImage = WeChatImage.createWeChatImage(map, assetFileDescriptor((map["source"] as? String).orEmpty()), context) val sourceImage = WeChatImage.createWeChatImage(map, assetFileDescriptor)
val thumbData = readThumbnailByteArray(call) val thumbData = readThumbnailByteArray(call)
val sourceByteArray = sourceImage.readByteArray() val sourceByteArray = sourceImage.readByteArray()
...@@ -249,13 +249,14 @@ internal interface FluwxShareHandler : CoroutineScope { ...@@ -249,13 +249,14 @@ internal interface FluwxShareHandler : CoroutineScope {
private suspend fun readThumbnailByteArray(call: MethodCall): ByteArray? { private suspend fun readThumbnailByteArray(call: MethodCall): ByteArray? {
val thumbnailMap: Map<String, Any>? = call.argument(keyThumbnail) val thumbnailMap: Map<String, Any>? = call.argument(keyThumbnail)
return thumbnailMap?.run { return thumbnailMap?.run {
val thumbnailImage = WeChatImage.createWeChatImage(thumbnailMap, assetFileDescriptor((thumbnailMap["source"] as? String).orEmpty()), context) val thumbnailImage = WeChatImage.createWeChatImage(thumbnailMap, assetFileDescriptor)
val thumbnailImageIO = ImagesIOIml(thumbnailImage) val thumbnailImageIO = ImagesIOIml(thumbnailImage)
compressThumbnail(thumbnailImageIO) compressThumbnail(thumbnailImageIO)
} }
} }
private suspend fun compressThumbnail(ioIml: ImagesIO) = ioIml.compressedByteArray(context, SHARE_IMAGE_THUMB_LENGTH) private suspend fun compressThumbnail(ioIml: ImagesIO) = ioIml.compressedByteArray(context, SHARE_IMAGE_THUMB_LENGTH)
// SESSION, TIMELINE, FAVORITE // SESSION, TIMELINE, FAVORITE
private fun setCommonArguments(call: MethodCall, req: SendMessageToWX.Req, msg: WXMediaMessage) { private fun setCommonArguments(call: MethodCall, req: SendMessageToWX.Req, msg: WXMediaMessage) {
msg.messageAction = call.argument<String?>("messageAction") msg.messageAction = call.argument<String?>("messageAction")
......
package com.jarvan.fluwx.io package com.jarvan.fluwx.io
import android.content.Context
import android.content.res.AssetFileDescriptor import android.content.res.AssetFileDescriptor
import android.util.Log import android.util.Log
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
...@@ -125,23 +124,12 @@ interface WeChatImage { ...@@ -125,23 +124,12 @@ interface WeChatImage {
// ASSET, // ASSET,
// FILE, // FILE,
// BINARY, // BINARY,
fun createWeChatImage(params: Map<String, Any>, assetFileDescriptor: AssetFileDescriptor, context: Context): WeChatImage { fun createWeChatImage(params: Map<String, Any>, assetFileDescriptor: (String) -> AssetFileDescriptor): WeChatImage {
// Map toMap() => {"source": source, "schema": schema.index, "suffix": suffix}; // Map toMap() => {"source": source, "schema": schema.index, "suffix": suffix};
val suffix = (params["suffix"] as String?) ?: ".jpeg" val suffix = (params["suffix"] as String?) ?: ".jpeg"
return when ((params["schema"] as? Int) ?: 0) { return when ((params["schema"] as? Int) ?: 0) {
0 -> WeChatNetworkImage(source = (params["source"] as? String).orEmpty(), suffix = suffix) 0 -> WeChatNetworkImage(source = (params["source"] as? String).orEmpty(), suffix = suffix)
1 -> { 1 -> WeChatAssetImage(source = assetFileDescriptor(((params["source"] as? String).orEmpty())), suffix = suffix)
// val source = (params["source"] as? String).orEmpty()
// val uri = Uri.parse(source)
// val packageName = uri.getQueryParameter("package")
// val subPath = if (packageName.isNullOrBlank()) {
// flutterAssets.getAssetFilePathBySubpath(uri.path.orEmpty())
// } else {
// flutterAssets.getAssetFilePathBySubpath(uri.path.orEmpty(), packageName)
// }
WeChatAssetImage(source = assetFileDescriptor, suffix = suffix)
}
2 -> WeChatFileImage(source = (params["source"] as? String).orEmpty(), suffix = suffix) 2 -> WeChatFileImage(source = (params["source"] as? String).orEmpty(), suffix = suffix)
3 -> WeChatMemoryImage(source = (params["source"] as? ByteArray) 3 -> WeChatMemoryImage(source = (params["source"] as? ByteArray)
?: byteArrayOf(), suffix = suffix) ?: byteArrayOf(), suffix = suffix)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论