使用pinterest应用程序打开pinterest链接(如果存在)-android

kar*_*tas 2 java android android-intent android-activity pinterest

我想知道是否存在相应的方法来打开带有pinterest应用程序的pinterest链接(如果已安装),或者通过浏览器打开(如果它不在Facebook之类的设备中)。对于Facebook,我使用以下代码

            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);
Run Code Online (Sandbox Code Playgroud)

小智 6

如果已安装,它将启动应用程序,否则将打开浏览器

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>")));
}
Run Code Online (Sandbox Code Playgroud)