0

我需要使用链接(包含一些参数)从电子邮件启动应用程序,例如 http://www.this-so-does-not-exist.com/something

在使用意图过滤器中的以下内容单击一封简单的电子邮件后,我可以启动我的应用程序。

<intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>

            <data
                android:host="www.this-so-does-not-exist.com/something"
                android:scheme="http"/>
        </intent-filter>

现在我想传递一些信息以及电子邮件链接,例如 http://www.this-so-does-not-exist.com/something?id=4545

我如何从我的 android 应用程序中读取它。

任何帮助都感激不尽。提前致谢。

4

2 回答 2

0

从这个答案中,我们得到意图字符串,然后解析 URL,如下所示。

if(getIntent() != null){
    String url = getIntent().getDataString(); // should be http://www.this-so-does-not-exist.com/something?id=4545
    List<NameValuePair> parameters = URLEncodedUtils.parse(new URI(url));
    for (NameValuePair p : parameters) {
        Log.i("MyApp", "Parameter Name: " + p.getName() + ", Parameter Value: " + p.getValue();
    }
}

使用它,您可以向 URL 添加任意数量的参数,并轻松检索它们以供使用。

于 2014-07-22T12:36:25.970 回答
0

getIntent().getData()从您的Activity遗嘱中,您将Uri获得用于启动您的应用程序的信息。查询参数可从各种方法上获得Uri例如getQueryParameter().

于 2014-07-22T12:30:13.713 回答