May 28, 2020

Launch one app from another app in android

By Mohit Agrawal

In this small tutorial learn how to launch one app from another app in android. I will be using Kotlin to demonstrate this. The final output will be like this. It has one button and on clicking it I am opening the YouTube app from my app. Let’s start the coding part.

android intent

Implementation

Create a new kotlin android project. Now design a simple button and give id as btnYoutube. Once you have created the button then go to the MainActivity.kt and in the onCreate method write this code block.

btnYoutube.setOnClickListener {
            val launchIntent = packageManager.getLaunchIntentForPackage("com.google.android.youtube")
            if (launchIntent != null) {
                startActivity(launchIntent)
            } else {
                Toast.makeText(this@MainActivity, "There is no package available in android", Toast.LENGTH_LONG).show()
            }
        }

Now let me explain to you that what are we doing here. On the click of a button, we have written the code which will trigger the launch intent activity. I am using the YouTube package name i.e “com.google.android.youtube” so that we can tell android which intent we want to launch. Now run the app and you will find it working.

So this is how you can launch one app from another app in android. Check out API call in android using volley.

Subscribe YouTube: More tutorials like this

I hope this blog post is useful for you, do let me know your opinion in the comment section below.
I will be happy to see your comments down below 👏.
Thanks for reading!!!