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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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());
回答2:
The URI is in the Intent data. Activity.getIntent().getData().