使用浏览器在选择器中打开 facebook link

Open facebook link in chooser with browsers

Сan 我们打开 facebook link 以便用于查看内容的应用程序的菜单选择仍然是 facebook 浏览器?标准启动

fun openLink(link: String) {
    Intent(Intent.ACTION_VIEW).apply {
        flags = Intent.FLAG_ACTIVITY_NEW_TASK
        data = Uri.parse(link)

        context.startActivity( this)
    }
 }

只打开浏览器,还有一些浏览器,例如chrome和edge,运行另一个,然后出现facebook(如果安装了),我唯一能找到的东西是直接打开 links 到 facebook,如果已安装,则无法选择应用程序打开 link

Intent(Intent.ACTION_VIEW).apply {
            flags = Intent.FLAG_ACTIVITY_NEW_TASK
            try {
                val applicationInfo: ApplicationInfo = 
                       packageManager.getApplicationInfo("com.facebook.katana", 0)
                if (applicationInfo.enabled) {
                    // 
                    data = Uri.parse("fb://facewebmodal/f?href=https://facebook.com/")
                }
            } catch (ignored: PackageManager.NameNotFoundException) {
                data = Uri.parse("https://facebook.com/")
            }

            startActivity(this)
        }
  1. what i have
  2. what i want and what chorme send after open facebook link

你熟悉EXTRA_INITIAL_INTENTS吗?创建两个单独的 Intents(如果存在并启用了 fb 应用程序)并加入它们

Intent chooserIntent = Intent.createChooser(browserIntent, "Open in...");
if (fbIntent != null) {
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { fbIntent });
}
startActivity(chooserIntent);

HERE and HERE

中的更多信息