open pinterest link with pinterest app if exist -

2019-07-15 03:02发布

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);

2条回答
Root(大扎)
2楼-- · 2019-07-15 03:36

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)

查看更多
迷人小祖宗
3楼-- · 2019-07-15 03:56

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>")));
}
查看更多
登录 后发表回答