In the Open Event Android App there is a section called “Manage events”, we direct the users to the Organizer’s app if the users have the app already installed otherwise we open the organizer’s app in the playstore. This way users are motivated to create events using the organizer’s app. Let’s see how this feature was implemented.
So when the user clicks on the menu item “Manage Events” startOrgaApp function is called with the package name of the organizer’s app as the argument. Android apps are uniquely identified by their package names in the playstore.
Let’s have a look at the startOrgaApp function that we are calling above. We are using a try/catch block here. We are opening the app in the try block if it is installed otherwise we throw ActivityNotFoundException and if this exception happens we will catch it and use the showInMarket function to show the Organizer’s app in the market.
Now since we know this will never raise an exception there is no try catch block as the app with this package name will always be there. We just need to create an intent with the required parameters and then just pass the intent to startActivity
Lastly we just need to add the XML code to create a menu item. It should contain the id so that we can reference it and the title that will be visible.
That’s it now you can open an app in the playstore if it is not installed or just open the app if the user has already installed the app.
- Vogella Intent tutorial – http://www.vogella.com/tutorials/AndroidIntent/article.html
- Official Android Documentation Intent – https://developer.android.com/guide/components/intents-filters
- Javatpoint intent tutorial – https://www.javatpoint.com/android-explicit-intent-example