简体   繁体   中英

Android : How to Launch My activity instead of Browser

I am new to android, I am designing an application in which i want to use broadcast receivers. By using this i want to launch my application when somebody clicks on browser (Default android browser). If anybody had done this, please help me.

Thanks in advance.

You can't intercept launches of the main browser, however, you can make your application handle intents for viewing URLs. To do this add something like this to AndroidManifest.xml in the section of your activity:

<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="http" />
    <data android:scheme="https" />
</intent-filter>

You can set an intent-filter for some url (using http scheme). By this way, if user browse on an identified url, your app will be launched instead of the webpage.

more details here: http://developer.android.com/guide/topics/intents/intents-filters.html#ifs and here: http://developer.android.com/guide/topics/manifest/data-element.html

Regards, Patrick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM