Created
August 27, 2019 12:28
-
-
Save IhwanID/e6d5045999024d6ef71d39b0d91cc8b7 to your computer and use it in GitHub Desktop.
Open Whatsapp Intent in Kotlin Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
val sendIntent = Intent().apply { | |
action = Intent.ACTION_SEND | |
putExtra(Intent.EXTRA_TEXT, "Hello Swapz") | |
putExtra("jid", "${data.phone}@s.whatsapp.net") | |
type = "text/plain" | |
setPackage("com.whatsapp") | |
} | |
startActivity(sendIntent) | |
}catch (e: Exception){ | |
e.printStackTrace() | |
val appPackageName = "com.whatsapp" | |
try { | |
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appPackageName"))) | |
} catch (e :android.content.ActivityNotFoundException) { | |
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName"))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment