我正在 Android 上构建一个应用程序,该应用程序有一个网络浏览器按钮,可以使用 google chrome 重定向到 amazon.com。现在我希望网络浏览器向我显示可供选择的可用浏览器列表。
我编写了代码,但不知何故我的三星 Galaxy A52s 没有触发选择选项。我转到“设置”>“应用程序”>“默认应用程序”,看到 Chrome 是默认浏览器,我重置了首选项,但仍在运行代码,但仍然没有获得选择选项。怎么做呢?我需要帮助。这是代码的一部分: // 设置按钮以隐式意图启动 Web 浏览器 binding.implicit.setOnClickListener(v -> { Uri 网站 = Uri.parse("http://www.amazon.com");
// Create an implicit intent to open the browser
Intent browserIntent = new Intent(Intent.ACTION_VIEW, website);
// Use an Intent Chooser to show the available apps to handle the request
Intent chooser = Intent.createChooser(browserIntent, "Open with");
// Launch the chooser with the ActivityResultLauncher
browserLauncher.launch(chooser);
});
return view;
}
确保选择器出现的步骤 检查已安装的浏览器:确保您的设备上安装了多个浏览器。如果 Chrome 是唯一的浏览器,则不会出现选择器。 清除浏览器的默认设置:即使在重置首选项之后,有时也需要清除单个应用程序的默认设置。转到“设置”>“应用程序”>“Chrome”>“默认打开”并清除默认值。对任何其他浏览器重复此操作。 修改您的代码:您的代码看起来基本正确, 爪哇
// 设置按钮以隐式意图启动 Web 浏览器
binding.implicit.setOnClickListener(v -> {
Uri website = Uri.parse("http://www.amazon.com");
// Create an implicit intent to open the browser
Intent browserIntent = new Intent(Intent.ACTION_VIEW, website);
// Use an Intent Chooser to show the available apps to handle the request
Intent chooser = Intent.createChooser(browserIntent, "Open with");
// Launch the chooser
startActivity(chooser);
});