publicdomain
publicdomain

Reputation: 1742

How to open any store using android intents / a market URI

Context: I am developing an efficient open-source android launcher (view on GitHub). In its settings-activity is a button labeled Install apps that is supposed to take the user to a store of his choice (F-Droid or the PlayStore).


Currently, the button is only capable of opening the PlayStore. Here's the corresponding code (minimal reproducible example):

// in the install buttons on-click listener:

val storeIntent = Intent(
  Intent.ACTION_VIEW,
  Uri.parse("https://play.google.com/store/apps/")
)
startActivity(storeIntent) // go to the store

Other posts on StackOverflow have shown me to use market:// URIs (from this answer) in order to open any store using an intent (and automatically let the user decide which store they want to go to). This is functional (and used in the app at another point) but not very helpful here, as we want to open the stores main / start page.

A plain market:// URI does not select any app to be opened and URIs starting with market://details only are capable of searching ?q=, filtering stores by categories ?c= and of displaying app-details.


Is there an URI / Intent that can be used to take users to any store's main page (the system suggests capable market-apps)?

Upvotes: 2

Views: 1379

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007359

Here's the corresponding code

Note that there is no requirement for the Play Store app to advertise an <intent-filter> matching this Intent structure. This Intent might launch a browser, if someday the Play Store removes that <intent-filter>. It also might crash with an ActivityNotFoundException, if the user does not have a suitable app (e.g., they are running a restricted profile and lack access to both the Play Store and a Web browser).

Is there an URI / Intent that can be used to take users to any store's main page (the system suggests capable market-apps)?

No, insofar as there is no requirement for any particular app store's app to advertise to other apps that they, indeed, are an app store.

You can try to use CATEGORY_APP_MARKET in a selector Intent try to pull in app stores:

    private fun launchGooglePlay() {
        val intent = Intent.makeMainSelectorActivity(
            Intent.ACTION_MAIN,
            Intent.CATEGORY_APP_MARKET
        )
        try {
            startActivity(intent)
        } catch (e: ActivityNotFoundException) {
            Log.e(tag, "launchGooglePlay()", e)
        }
    }

(from this gist)

However, based on a quick scan of the F-Droid manifest, I don't think that they will respond to this. If they don't, you could contribute a change to their project so that they will. However, whether Huawei's, Samsung's, or other app stores support this Intent approach is up to their developers.

Upvotes: 1

Related Questions