Not able to find any source where it is clear about adding implicit intent to open another app from my app in kotlin.
Manifest.xml
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
MainActivity.kt
val location = Uri.parse("com.whatsapp")
val mapIntent = Intent(Intent.ACTION_VIEW, location)
try {
startActivity(mapIntent)
} catch (e: ActivityNotFoundException) {
intent = Intent(Intent.ACTION_VIEW)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.setData(Uri.parse( "market://details?id=" +"com.whatsapp"))
startActivity(intent)
}
val i = packageManager.getLaunchIntentForPackage("com.whatsapp")
i?.putExtra("data", "This is from first app")
if(i !=null){
startActivity(i)
}
else{
intent = Intent(Intent.ACTION_VIEW)
intent.setData(Uri.parse("market://details?id=" +"com.whatsapp"))
startActivity(intent)
}
It opens WhatsApp directly in playstore instead of opening the app.