Getting data from an implicit intent

2020-02-11 07:41发布

I'm writing an application that will be invoked when a specific website is accessed in the android browser. I've configured my intent filters to make this happen, but I'm having trouble finding details on how the information from the browser is transfered to my application ... since I need the exact website address that the browser was trying to access. I'm assuming that this data is stored in the intent extras, but to access those I need to know what the name of the keys are to get the info and what format, etc. Anyone know where this is documented? I'm guessing it's standardized.

2条回答
贼婆χ
2楼-- · 2020-02-11 08:03

The URI is in the Intent data. Activity.getIntent().getData().

查看更多
啃猪蹄的小仙女
3楼-- · 2020-02-11 08:05

Yes you can get the data but you might need this in your manifest if you are doing implicit intents...

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

And then if you want the data to make a new URL do this inside you activity:

Uri data = this.getIntent().getData();
url = new URL(data.getScheme(), data.getHost(), data.getPath());
查看更多
登录 后发表回答