【问题标题】:Launching Android Application from link or email从链接或电子邮件启动 Android 应用程序
【发布时间】:2013-02-04 07:07:53
【问题描述】:

我一直在尝试通过电子邮件链接或某些社交网站上的帖子来启动应用程序。问题是在某些设备或 android 上的某些 gmail 应用程序中不显示我指定的锚标记或链接。

我为我的活动设置的intent-filter 如下:

 <action android:name="android.intent.action.VIEW" />
 <category android:name="android.intent.category.DEFAULT" />
 <category android:name="android.intent.category.BROWSABLE" />
 <data android:scheme="myappname" />

我正在发送带有此锚标记的电子邮件

myappname://processtobedone/?id=1

它适用于我在华为设备上的电子邮件应用程序,但在设备的默认 gmail 应用程序中,它没有显示它有一个链接,并且在某些设备中,它默认附加 https: 作为标签的后缀并启动浏览器。

【问题讨论】:

标签: android email launch


【解决方案1】:

您可以使用&lt;intent-filter&gt; 来标识您控制的 URL,而不是使用自定义方案:

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>

    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>

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

然后,指向http://www.this-so-does-not-exist.com/something 的链接将在安装了您的应用程序的设备上显示您的应用程序(在选择器中以及 Web 浏览器中),并在没有安装您的应用程序的设备上显示您的网页。

【讨论】:

  • 感谢@CommonsWare 延迟回复。我会试试这个。
  • 您好,感谢您的回答,它在大多数设备上都可以正常工作,但并非完全适用,因为它不适用于 HTC EVO 4G。每当我点击链接时,它都会直接打开浏览器,我知道为什么会这样。还检查了是否设置了任何默认值,也没有设置。
  • @Dinash:这种方法可能不适用于各种美国发货的 HTC 设备,因为 Apple 获得了进口禁令。见commonsware.com/blog/2012/07/23/…commonsware.com/blog/2012/07/24/…
【解决方案2】:

创建一个真正的链接 (http:) 访问您控制的网站,例如 amazon s3 上的静态网站,使用该网站上的 javascript 检测 android 用户代理,然后重定向到带有锚标记的链接。

【讨论】:

  • 您甚至不需要 JavaScript。如果&lt;intent-filter&gt;有网页URL而不是自定义scheme,用户可以选择直接打开应用。
  • @CommonsWare 啊,这就是 instagram 的工作方式。我一直想知道这是一个怎样的选择
  • @CommonsWare 你能告诉我如何定义 url 而不是自定义方案。
【解决方案3】:
<activity
android:name=".SplashEmailActivity"
android:screenOrientation="portrait"
android:exported="true"
android:launchMode="singleInstance" android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
android:windowSoftInputMode="stateHidden|adjustResize" >

<intent-filter>

<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="http"  android:host="your.domain.name"/>

</intent-filter>

</activity>

【讨论】:

    【解决方案4】:

    要在设备上触发应用程序链接,例如您的案例myappname://processtobedone/?id=1,最简单的方法是创建一个基本的html页面文件(名称为deeplink_test.html)并发送到您的电子邮件,然后打开此电子邮件然后点击html文件,用Chrome浏览器打开,点击锚链接。

    <html>
        <head>
            <title>DeepLink Test</title>
        <head>
        <body>
            <a href="myappname://processtobedone/?id=1">run deeplink</a>
        <body/>
    </html>
    
    

    【讨论】:

    • 电子邮件应用程序会删除这个,例如 gmail 会删除这个
    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 2012-01-04
    • 2011-01-14
    • 1970-01-01
    • 2014-09-13
    • 1970-01-01
    • 2018-02-02
    • 2012-07-30
    相关资源
    最近更新 更多