通过Android中的URL方案打开我的应用 [英] Open my app from URL scheme in Android

查看:227
本文介绍了通过Android中的URL方案打开我的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道关于此有几个问题,但是没有一个问题可以帮助解决我的问题。



我希望能够点击以下链接电子邮件/文本/浏览器,然后打开我的应用。



我有 AndroidManifest.xml 代码:

 <!-启动活动-> 
< activity
android:name =。ui.SplashActivity
android:label = @ string / app_name
android:theme = @ style / SplashTheme
android:launchMode = singleTask>

< ;!-启动器意图过滤器->
< intent-filter>
< action android:name = android.intent.action.MAIN />
< category android:name = android.intent.category.LAUNCHER />
< / intent-filter>

< ;!-分支URI方案->
< intent-filter>
< data android:scheme = myscheme android:host = open />
< action android:name = android.intent.action.VIEW />
< category android:name = android.intent.category.DEFAULT />
< category android:name = android.intent.category.BROWSABLE />
< / intent-filter>
< / activity>

这似乎遵循文档此处准确,但是,当我使用Chrome(或Android浏览器)浏览到 myscheme://打开,我的应用程序无法打开,而是获取 myscheme:// open 的Google搜索结果。



谁能看到我在这里遗失的难题? 如何让我的应用程序通过URI打开?



小更新:



阅读 ,我发现将Chrome浏览到 market:// details?id = com.myapp 不会打开应用商店。而是返回Google搜索结果-与尝试直接启动我的应用程序时相同。这令人困惑。 我是否缺少允许深度链接的全局操作系统设置?

解决方案

Chrome无法从以下位置打开应用手动输入的URI方案。实际上,手动输入的链接将从不在Chrome中启动外部应用。这是设计使然-不论出于何种原因,Chrome团队都认为输入地址后应始终将用户保留在浏览器中。



您可以在某种程度上解决此问题,方法是:将深层链接置于用户驱动操作的后面(例如,标准< a> 标记),但是Chrome具有自己的标准,即Chrome Intent,代替使用。



在其他应用程序中,是否有自定义URI方案取决于应用程序,具体取决于所使用的设备。



被标识为可点击链接。为了获得最佳兼容性,您需要将其包装在带有重定向的常规 http:// 链接中。



如果您想深入了解深层链接的复杂性,请这篇文章是一个很好的起点。如果您只是想让它不费吹灰之力地工作,请 Branch.io (完整说明:我正在分支团队)通过免费服务解决了这个问题。


I know there are several questions on SO about this, but none of them are helping to resolve my issue.

I want to be able to click a link from an email/text/browser and open my app.

I have the AndroidManifest.xml code:

    <!-- Splash Activity -->
    <activity
        android:name=".ui.SplashActivity"
        android:label="@string/app_name"
        android:theme="@style/SplashTheme"
        android:launchMode="singleTask">

        <!-- Launcher intent filter -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <!-- Branch URI scheme -->
        <intent-filter>
            <data android:scheme="myscheme" android:host="open" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity>

This appears to follow the documentation here exactly, however, when I use Chrome (or Android Browser) to browse to myscheme://open, my app does not open, and instead I get Google search results for myscheme://open.

Can anyone see what piece of the puzzle I am missing here? How can I get my app to open via URI?

Small update:

After reading this, I have found that navigating Chrome to market://details?id=com.myapp does not open the play store. Instead it returns Google search results - the same as when trying to launch my app directly. Which is confusing. Am I missing a global OS setting to allow deep linking?

解决方案

Chrome does not open apps from manually-entered URI schemes. In fact, a manually-entered link will never launch an external app in Chrome. This is by design — for whatever reason, the Chrome team feels users should always be kept inside the browser after entering an address.

You can work around this to some extent by putting the deep link behind a user-drive action (a standard <a> tag, for example), but the Chrome has its own standard called Chrome Intents that you are supposed to use instead. Depending on the device you are using, this could also be the case for the standard browser.

In other apps, it's up to the app in question whether a custom URI scheme is identified as a 'clickable link'. For best compatibility, you'll want to wrap it inside a regular http:// link with a redirect.

If you're interested in an in-depth explanation of the complications around deep linking, this post is a good place to start. If you just want it to work without a lot of extra effort, Branch.io (full disclosure: I'm on the Branch team) solves this problem as a free service.

这篇关于通过Android中的URL方案打开我的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆