Launch Activity From URL

拈花ヽ惹草 提交于 2019-12-05 08:09:10

I use this in my manifest.xml file:

<activity android:name=".SomeName">
    <intent-filter>
        <category android:name="android.intent.category.ALTERNATIVE" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:host="google.com" android:scheme="http" />  
    </intent-filter>
</activity>

This will start activity SomeName. I don't use www in the android:host part maybe that will make a difference.

When the activity starts you can get the data that's behind the .com using (for example):

Uri data = getIntent().getData();
if(data != null && data.getPathSegments().size() >= 2){
    List<String> params = data.getPathSegments();
    String somestuff = params.get(0);
}

Edit: If you wan't to be able to check the host from within the activity, use this method:

data.getHost();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!