0

Possible Duplicate:
How can I open a URL in Android’s web browser from my application?
Start the android browser

I check some reference I use below code to call Default Browser in main activity.

        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);

And then modify 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>

But I get the Log error:

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

How to call Default Browser in main activity?

Community
  • 1
  • 1
Li Che
  • 727
  • 10
  • 24

1 Answers1

0

What do you mean by default? The one the user declared as default? If yes then this is the code:

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

You don't actually need to add intents to the application XML, that means an other thing. You might want to read through the docs to learn what intent-filters are for.

SztupY
  • 10,291
  • 8
  • 64
  • 87