如何在主要活动中调用默认浏览器?

时间:2012-12-21 09:43:46

标签: android browser

  

可能重复:
  How can I open a URL in Android’s web browser from my application?
  Start the android browser

我检查一下我在代码下面使用的一些引用,在主要活动中调用默认浏览器。

        Intent intent= new Intent();        
        intent.setAction("android.intent.action.VIEW");    
        Uri content_url = Uri.parse("www.baidu.com");   
        intent.setData(content_url);           
        intent.setClassName("com.android.browser","com.android.browser.FMSActivity");   
        startActivity(intent);

然后修改xml:

               <intent-filter>
                  <action android:name="android.intent.action.VIEW" />
                  <category android:name="android.intent.category.DEFAULT" />
                  <category android:name="android.intent.category.BROWSABLE" />
                  <data android:scheme="file" />
              </intent-filter>

但是我得到了Log错误:

12-21 05:54:56.367: E/AndroidRuntime(277): at sz.zd.SzActivity.onCreate(SzActivity.java:19)

如何在主要活动中调用默认浏览器?

1 个答案:

答案 0 :(得分:0)

默认是什么意思?用户声明为默认值的那个?如果是,则这是代码:

Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.addCategory(Intent.CATEGORY_BROWSABLE);
i.setData(Uri.parse(THE_URL));
startActivity(i);

您实际上不需要向应用程序XML添加意图,这意味着另一件事。您可能希望通读文档来了解intent-filters的用途。