Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(share_plus) sharing content on huawei or honor vendor which changed the default intent of Intent.ACTION_SEND #3417

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading