我想知道是否有相应的方法可以打开 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);
最佳答案
如果已安装,这将启动应用程序,否则将打开浏览器
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>")));
}
关于java - 使用 pinterest 应用程序打开 pinterest 链接(如果存在)- android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31638409/