0

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.

  • `"com.whatsapp"` is not a valid `Uri`, so the first half of your Kotlin code is wrong. The `getLaunchIntentForPackage()` call might be correct, though [on Android 11 and higher you will need a `` element in the manifest to be able to make that call](https://commonsware.com/R/pages/chap-package-001.html). – CommonsWare Sep 14 '22 at 22:21
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 15 '22 at 01:14
  • @Community I want to know where I am being wrong in the code part for which implicit intent is not working properly. – Vivek Jaiswal Sep 15 '22 at 05:55
  • @CommonsWare please give any suggestions or solutions if possible because the link which you gave didn't solve the issue. – Vivek Jaiswal Sep 15 '22 at 10:34
  • Still not got any solutions to my problem, please anyone give some suggestions to my problem @CommonsWare – Vivek Jaiswal Sep 15 '22 at 22:44

0 Answers0