简体   繁体   English

从隐式意图中获取数据

[英]Getting data from an implicit intent

I'm writing an application that will be invoked when a specific website is accessed in the android browser. 我正在编写一个应用程序,当在Android浏览器中访问特定网站时将调用该应用程序。 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? 我假设这些数据存储在intent extras中,但要访问那些我需要知道密钥的名称是什么来获取信息和格式等等。任何人都知道这在哪里被记录? 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>

And then if you want the data to make a new URL do this inside you activity: 然后,如果您希望数据生成新的URL,请在您的活动中执行此操作:

Uri data = this.getIntent().getData();
url = new URL(data.getScheme(), data.getHost(), data.getPath());

The URI is in the Intent data. URI位于Intent数据中。 Activity.getIntent().getData(). Activity.getIntent()的getData()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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