如何在Android中打开深度链接uri?
例如,有一个uriexample://activityone?foo=bar可通过此adb命令打开应用程序并启动其中一项活动如何在Android中打开深度链接uri?,android,uri,deep-linking,Android,Uri,Deep Linking,例如,有一个uriexample://activityone?foo=bar可通过此adb命令打开应用程序并启动其中一项活动 adb shell am start -W -a android.intent.action.VIEW -d "example://activityone?foo=bar" com.example.deeplinking 通过此uri(example://activityone?foo=bar)?如何将此uri放入电子邮件中,当单击它时,它将启动应用程序?非标准URL方
adb shell am start -W -a android.intent.action.VIEW -d "example://activityone?foo=bar" com.example.deeplinking
通过此uri(example://activityone?foo=bar)?如何将此uri放入电子邮件中,当单击它时,它将启动应用程序?非标准URL方案(即
示例://
的内容)并不总是被视为链接。你最好的选择是以某种方式将该URL包装在应用程序可以识别的链接中(http://
或https://
),然后注意稍后打开应用程序,通常是通过某种自动重定向的方式。这就是我们处理问题的方式,以确保无论链接在何处打开,应用程序始终启动。首先,您应该阅读相关文档:。特别是“接收隐含意图”一节
正如其他人所说,为此使用自定义方案存在问题
- 它们并不总是被视为链接
- 你不会像拥有域名(主机)一样拥有它们
<activity android:name="com.example.app.ActivityOne">
<intent-filter>
<data android:scheme="http"/>
<data android:host="example.com"/>
<data android:path="/activityone"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
由于这是一个http链接,系统将要求用户选择使用哪个应用打开它(您的应用或他们首选的浏览器)。如果他们选择了你的应用程序,它将启动ActivityOne,可以像这样获取查询数据
public class ActivityOne extends Activity {
@Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
Uri uri = intent.getData();
String foo = uri.getQueryParameter("foo");
}
}
如果您在意向过滤器中使用自定义方案,那么您(很可能)将是唯一注册以处理该意向的应用程序,用户将不必选择您的应用程序。但是,在电子邮件中包含带有自定义方案的链接对您来说要困难得多。大多数电子邮件客户端不会将任何带有自定义方案的内容识别为链接,也不会单击该链接。
嵌入电子邮件时,这不起作用。为确保电子邮件兼容性,请使用real deeplink或chrome意图:您能举个例子吗?链接中有示例我如何将此uri放入电子邮件中,以及当单击时,它将启动应用程序?我已经更新了答案,在单击时只包含链接和有关应用程序选择/启动过程的更多信息。您可以通过电子邮件发送给自己进行测试。如果您使用的是gmail(可能还有其他电子邮件客户端),您必须明确告诉它您想要http://example.com/activityone?foo=bar
将被视为链接而不是纯文本。突出显示文本,然后单击工具栏下的“发送”按钮旁边的“插入链接”。我知道http会起作用,我在发布这个问题之前就这么做了。我正在寻找如何打开自定义uri(example://activityone?foo=bar),我希望能够打开深层链接,即使方案不是http。问题不在于应用程序中的设置。问题是,任何自定义方案都很可能无法在任何SMS或电子邮件客户端中单击。看见
public class ActivityOne extends Activity {
@Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
Uri uri = intent.getData();
String foo = uri.getQueryParameter("foo");
}
}