gpt4 book ai didi

android - 从 Android 应用程序打开 native 浏览器

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:59:02 26 4
gpt4 key购买 nike

我有一部安装了多个浏览器的 Android 手机,我可能会也可能不会将浏览器设置为默认浏览器。

所以,我的问题是..

  1. 在我的应用程序中,如何强制仅在 NATIVE android 浏览器中打开链接?
  2. 有什么方法可以知道浏览器是否设置为默认浏览器?

最佳答案

From my App, How do I force open a link only in the NATIVE android browser?

Intent intent = new Intent();
ComponentName comp = new ComponentName("com.google.android.browser","com.google.android.browser.BrowserActivity");
intent.setComponent(comp);
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
Uri uri = Uri.parse(url);
intent.setData(uri);
try
{
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}

Is there a way I can know if there is a browser set to default or not?

PackageManager packageManager = getPackageManager();

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("URL"));

List<ResolveInfo> list = packageManager.queryIntentActivities(intent, 0);

if (list.size() > 0) {
for (ResolveInfo resolveInfo : list) {
resolveInfo.isDefault();// will let u know if the app is set to default
}

} else {
//No apps available
}

关于android - 从 Android 应用程序打开 native 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10332868/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com