open pinterest link with pinterest app if exist -

2019-07-15 03:07发布

问题:

I would like to know if there is a corresponding way to open a pinterest link with pinterest app if is installed, or with the browser if it is not in the device like Facebook. For Facebook I use the following code

            final String urlFb = "fb://page/" + "profile_id";
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(urlFb));

            // If a Facebook app is installed, use it. Otherwise, launch
            // a browser
            final PackageManager packageManager = getPackageManager();
            List<ResolveInfo> list =
                    packageManager.queryIntentActivities(intent,
                            PackageManager.MATCH_DEFAULT_ONLY);
            if (list.size() == 0) {
                final String urlBrowser = "https://www.facebook.com/" + "profile id";
                intent.setData(Uri.parse(urlBrowser));
            }

            startActivity(intent);

回答1:

I already search a while ago for this problem, and I think Pinterest does not propose any way to start it like you are doing it with the Facebook app.

Unless pinterest offer this feature in the future, you will need to only create a simple web intent, and the user will be proposed to open it with his browser, or Pinterest app if the user has the app installed. (if Pinterest used this in their app : Web Intents, and in my memories, they did)



回答2:

This will launch the app if installed, otherwise it will open the browser

try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("pinterest://www.pinterest.com/<profile-name>")));
} catch (Exception e) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.pinterest.com/<profile-name>")));
}