Skip to content

Commit

Permalink
fix(share_plus) sharing content on huawei or honor vendor which chang…
Browse files Browse the repository at this point in the history
…ed the default intent of Intent.ACTION_SEND
  • Loading branch information
wangxin6 committed Jan 2, 2025
1 parent 7c8894b commit 7db8a68
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
}

0 comments on commit 7db8a68

Please sign in to comment.