casolorz
casolorz

Reputation: 9594

How can I open the Play Store to show an app given its custom url scheme?

I have a web browser app, some sites will redirect to their own custom scheme, like customscheme://...... On Chrome it will open the Play Store straight into their app listing or the actual app if the app is installed. When I try to create an Intent for customscheme://..... I just get an ActivityNotFoundException, so I'm guessing I need to open the Play Store and pass it the custom scheme. But how do I do that? I only know how to open the Play Store and pass it a package, but I have no idea what the package is for that custom scheme.

Thanks.

Edit: Just to clarify my question, how can I tell the Play Store to show the store listing for a given custom url scheme without me knowing the package name?

Edit: Wanted to explain a bit further based on comments and one answer. First, like I said, I know how to open the Play Store passing the package, so that isn't the issue. I need to somehow do that using a custom url scheme, not a package name.

To understand what I want to do, open Chrome or Firefox and go to reddit.com and then reddit will ask you to open their app at the bottom. If you press open app, it will open the reddit app if it is available (I know how to do that) but if not, it will open the Play Store (I don't know how to do that).

Edit: Looks like most websites are also opening market:// and that is what those browsers are using, not the customscheme://.

Upvotes: 2

Views: 1545

Answers (2)

Mayank Kumar Chaudhari
Mayank Kumar Chaudhari

Reputation: 18696

Ok. So based on your latest edit following is the custom url of Reddit app

https://reddit.app.link/?domain=www.reddit.com&geoip_country=IN&user_agent=Mozilla%2F5.0%20(Android%209%3B%20Mobile%3B%20rv%3A68.0)%20Gecko%2F68.0%20Firefox%2F68.0&base_url=%2F&referrer_domain=&referrer_url=&language=&dnt=true&compact_view=true&adblock=false&session_id=sHlE5GcvBjkzL3wFGB&loid=00000000006ldndtwb&loid_created=1590598522358&reddaid=T7Y3HFNPYLDI5CIB&utm_term=treatment_4&utm_medium=mweb&utm_source=xpromo&utm_name=mweb_xpromo_revamp_v3&campaign=mweb_xpromo_revamp_v3&channel=xpromo&feature=mweb&keyword=treatment_4&%24og_redirect=https%3A%2F%2Fwww.reddit.com%2F&%24deeplink_path=%2F&%24android_deeplink_path=reddit%2F&mweb_loid=00000000006ldndtwb&mweb_loid_created=1590598522358&mweb_user_id36=&mweb_user_name=&tags=app_selector_modal_xpromo_listing&utm_content=app_selector_modal_xpromo_listing

Actually the browser isn't doing anything special to open playstore. This url has a big upload that is sent to reddit.com where it loggs the referer url and all other tracking stuff that it gathered and then redirects it to playstore.

All you need to do is follow this redirect.

Read following article by Mozilla for more information on redirects

https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections

Hope this solves your issue.

Update Android WebView, how to handle redirects in app instead of opening a browser

Also refer to above question for more details on handeling redirects in android app.

Try option 1: In shouldOverrideUrlLoading method as in above question or

Option 2: look for the location in the redirected url in the response returned by the server - that's what browser opens or triggers and intent to open.

Hope this solves your doubt. Let me know if something is not clear.

Upvotes: 1

VolodymyrH
VolodymyrH

Reputation: 2019

I'm not sure how to do it from web side. But you should create intent with action view and your scheme is (Android logic):

try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
} 

Also, I don't quite understand what do you want to do without the package name as it's the exact thing by which you can find the app. But you can just open play store.

Upvotes: 0

Related Questions