From 7db8a688e5a7c3ee1751659ae273d4af35f65dce Mon Sep 17 00:00:00 2001 From: wangxin6 Date: Thu, 2 Jan 2025 23:59:18 +0800 Subject: [PATCH] fix(share_plus) sharing content on huawei or honor vendor which changed the default intent of Intent.ACTION_SEND --- .../dev/fluttercommunity/plus/share/Share.kt | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt index 59bdb1e914..c8a8ec0839 100644 --- a/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt +++ b/packages/share_plus/share_plus/android/src/main/kotlin/dev/fluttercommunity/plus/share/Share.kt @@ -81,7 +81,11 @@ internal class Share( } else { Intent.createChooser(shareIntent, null /* dialog title optional */) } - startActivity(chooserIntent, withResult) + startActivity(chooserIntent.apply { + getAvailableOemChooser()?.let { + action = it.action + } + }, withResult) } @Throws(IOException::class) @@ -155,7 +159,11 @@ internal class Share( ) } } - startActivity(chooserIntent, withResult) + startActivity(chooserIntent.apply { + getAvailableOemChooser()?.let { + action = it.action + } + }, withResult) } private fun startActivity(intent: Intent, withResult: Boolean) { @@ -251,4 +259,20 @@ internal class Share( file.copyTo(newFile, true) return newFile } + + enum class OemChooser( + val action: String, + val packageName: String, + ) { + HUAWEI("com.huawei.intent.action.hwCHOOSER", "com.huawei.android.internal.app"), + HIHONOR("com.hihonor.intent.action.hwCHOOSER", "com.hihonor.android.internal.app") + } + + + private fun getAvailableOemChooser(): OemChooser? = + OemChooser.values().firstOrNull { + val resolveInfo = context.packageManager.resolveActivity(Intent(it.action), PackageManager.MATCH_DEFAULT_ONLY) + + return@firstOrNull resolveInfo?.activityInfo?.packageName == it.packageName + } }