Opening the Play Store Programmatically in Xamarin Forms
Recently a student of mine asked a fascinating question that I hadn’t come up with, but that seemed to be easily implementable and super useful in at least one typical scenario: send your users over to the Play Store to get the latest available update to your app.
Now, the code that I will introduce in this post is not only useful for that, of course. The code will be able to open the Play Store and show any app that you want (you just have to get their package id which is super easy). I will also introduce a slightly different version of this implementation so that you can open the Play Store showing all the apps listed under a specified publisher.
Opening the Play Store
Let's dive right in. This code proved so simple thanks to some neat implementation from the Xamarin Forms package that that introduction was longer than the explanation that is coming next:
Getting the Package Id
If you want to open the Play Store showing a particular app, you will first need the package id. If it is your app the want that you want to show, you already have that over in your manifest (formatted something like com.lalorosas.MySuperSecretApp).
If, on the other hand, you want to display some other app, you can always find that package id over in your browser by navigating to the Google Play Store (play.google.com) and searching for the app you want. The url will contain that package id.
Once you have the id, all you need to do is add the following line of code to wherever you need it to be (typically the execute function to a command that you have bound to a button).
And yes, that is it.
Now, as I mentioned, you may want to open the Play Store for a different reason: maybe to show all the apps you (or anyone else) have listed. In that case, a similar code will be needed, only this time, instead of requesting some details for a particular id, you will perform a search and pass a query:
There you have it. Of course, you should keep in mind that this will only work on an Android device, so make sure you make the proper evaluations when executing this shared code.