1

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://.

Mayank Kumar Chaudhari
  • 16,027
  • 10
  • 55
  • 122
casolorz
  • 8,486
  • 19
  • 93
  • 200
  • Do you know if this is supported by Firefox? – tynn May 26 '20 at 18:10
  • Yes Firefox does it fine. For example go to reddit and press the open app button at the bottom and you'll see it opens the Play Store listing for it. – casolorz May 27 '20 at 16:42

2 Answers2

1

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.

Mayank Kumar Chaudhari
  • 16,027
  • 10
  • 55
  • 122
  • I guess reddit was a bad example as they are doing more complex things, first they redirect there, then they redirect to `reddit://reddit/?link_click_id=....` and to the `market://` scheme as well. If I go to nbc.com and click use the nbc app then it does the same, it opens `nbctve://home?link_click_id=...` and also `market://...` so maybe that is what all those sites are doing. I'll try to test a site that doesn't do it that way. – casolorz May 27 '20 at 19:04
  • Tested a bunch of sites and they all seem to be doing that. My issue was with a site that only has a `customscheme://..` but it doesn't interfere with the page functioning if I ignore it. Chrome and Firefox appear to ignore that `customscheme://` loading on that site, so they must only be following it if some app can handle it. – casolorz May 27 '20 at 19:13
  • I was wrong, Firefox doesn't handle that `customscheme://` well, it just redirects to a page that doesn't work, which is what I was doing before I started looking into this. Chrome must be checking if the custom scheme can be resolved. – casolorz May 27 '20 at 19:28
  • If the answer was helpful you may consider awarding a bounty so that it may not go in vein. – Mayank Kumar Chaudhari May 28 '20 at 15:50
0

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.

VolodymyrH
  • 1,927
  • 2
  • 18
  • 47
  • I don't know the package name. My app is a browser. User clicks link and the link is for `customscheme://.....` somehow Chrome can open either that app or the Play Store for the right store listing. I don't know how to do that. – casolorz May 27 '20 at 16:39
  • To make this more clear, open reddit.com on Chrome (if you don't have the reddit app) and press the open app button at the bottom. – casolorz May 27 '20 at 16:44