设置默认浏览器编程活动 [英] Setting default browser for activity programmatically

查看:186
本文介绍了设置默认浏览器编程活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序,并在其他功能我需要在外部Web浏览器中打开某些网址。我可以通过编程设置为默认应用程序,这样用户将无法从现有的浏览器的列表中进行选择?我的意思是,我只想为我的应用程序,但不是为整个操作系统设置的默认浏览器。

I'm developing an android app and among other functionality I need to open some urls in external web browser. Can I programmatically set a default application for that, so the user won't be able to choose from the list of available browsers? I mean, I want to set default browser only for my app but not for the whole operating system.

推荐答案

是的,因为这可以迫使你的应用程序始终开放原生的Andr​​oid浏览器只。为此,您必须确定启动活动浏览器应用程序,这样的事情:

Yes, for this you can force your application to always open native android browser only. For this you have to identify the launching Activity of Browser application, something like this:

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.google.android.browser","com.google.android.browser.BrowserActivity"));
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();
}

这篇关于设置默认浏览器编程活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆