I am trying to share some text, In Android 10 always show max 3 apps in my mobile have WhatsApp but this not displaying here
This code is properly working in below 10 devices but could not find the reason why in android 10 is filtering out.
fun onShareClick() {
val intentShareList = ArrayList<Intent>()
val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.type = "text/plain"
val resolveInfoList = packageManager.queryIntentActivities(shareIntent, 0)
for (resInfo in resolveInfoList) {
val packageName = resInfo.activityInfo.packageName
val name = resInfo.activityInfo.name
if (packageName.contains("com.facebook") ||
packageName.contains("com.twitter.android") ||
packageName.contains("com.google.android.gm") ||
packageName.contains("com.android.mms") ||
packageName.contains("com.whatsapp")
) {
val intent = Intent()
intent.component = ComponentName(packageName, name)
intent.action = Intent.ACTION_SEND
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_SUBJECT, "Your Subject")
intent.putExtra(Intent.EXTRA_TEXT, "Your Content")
intentShareList.add(intent)
}
}
if (intentShareList.isEmpty()) {
Toast.makeText(this@MainActivity, "No apps to share !", Toast.LENGTH_SHORT).show()
} else {
val chooserIntent = Intent.createChooser(intentShareList.removeAt(0), "Share via")
chooserIntent.putExtra(
Intent.EXTRA_INITIAL_INTENTS,
intentShareList.toTypedArray()
)
startActivity(chooserIntent)
}
}
In the intentShareList
contains WhatsApp info but not displaying
I think you should create your chooser using the initial intent and add your intentShareList as extra, like this:
val chooserIntent = Intent.createChooser(shareIntent, "Share via")
chooserIntent.putExtra(
Intent.EXTRA_INITIAL_INTENTS,
intentShareList.toTypedArray()
)
startActivity(chooserIntent)
I think it will bring what you want. Let me know if it helps :)
EDIT: Even if you put on your shareIntent a inicial EXTRA_INTENT and a type, Android Q will ignore what you added on EXTRA_INITIAL_INTENTS, so it wont help
I was reading about this on that issue and I think it wont be fixed, take a look = https://issuetracker.google.com/issues/134367295
Also, there some information on documentation that says using EXTRA_INITIAL_INTENTS to personalized data is not recomended, and its was made to helping share links and it can reduce the apps who will appear, take a look = https://developer.android.com/training/sharing/send
Well, Im very sad about that, Idk what do to also, maybe a unique text... :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With