从隐含的意图获取数据意图、数据

2023-09-06 05:34:24 作者:毕业季,加油!

我在写的时候一个特定网站在Android浏览器访问会被调用的应用程序。我已经配置了我的意图过滤器要做到这一点,但我无法找到如何从浏览器中的信息转移到我的应用程序的详细信息......因为我需要确切的网站地址,浏览器正试图访问。我假定这些数据存储在额外的意图,但访问那些我需要知道什么键的名称都得到信息,什么格式等任何人都知道,这是记录?我猜它的标准化。

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.

推荐答案

是的,你可以得到的数据,但你可能需要这在你的清单,如果你正在做的隐含意图...

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>

,然后如果你想要的数据做一个新的URL做到这一点你内心活动:

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