I find a lot of questions on StackOverflow showing how to open whatsapp in a given contact, but what I need is to launch it main screen (contact list).
I am on a fragment and I have tried the following:
1 Intent with category LAUNCHER
fun openWhats() {
val intent = Intent(Intent.LAUNCHER )
intent.setPackage("com.whatsapp")
activityResultLauncher.launch(intent)
}
2 Intent with category MAIN
fun openWhats() {
val intent = Intent(Intent.MAIN)
intent.setPackage("com.whatsapp")
activityResultLauncher.launch(intent)
}
ERROR: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.MAIN pkg=com.whatsapp }
3 Using Intent with api.whatsapp and category ACTION_VIEW
fun Fragment.openWhats() {
Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("https://api.whatsapp.com")
}.also {
startActivity(it)
}
}
ERROR: Cannot open link
4 Using getLaunchIntentForPackage()
fun Fragment.openApp(packageName: String): Boolean {
val manager = requireActivity().packageManager
return try {
val i = manager.getLaunchIntentForPackage(packageName) ?: return false
i.addCategory(Intent.CATEGORY_LAUNCHER)
requireActivity().startActivity(i)
true
} catch (e: ActivityNotFoundException) {
false
}
}
Does not work
Any idea how to achieve this?