【问题标题】:How to start my Android application when a link clicked from external app like whatsapp or facebook?从whatsapp或facebook等外部应用程序单击链接时如何启动我的Android应用程序?
【发布时间】:2018-01-26 16:35:48
【问题描述】:

我在清单文件中使用以下意图过滤器使用深度链接概念。

<activity
        android:name=".MyActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateAlwaysHidden" >
        <intent-filter android:label="@string/app_name">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:host="test.myapp.com"
                android:scheme="http"
                />
        </intent-filter>
    </activity>

这有助于我在点击 whats 应用程序中的链接时显示我的应用程序, 但它会在列表中显示其他应用程序,如 chrome、Internet 等。 我怎样才能只在点击其他应用程序(如whats app)中的链接后直接访问我的应用程序?

【问题讨论】:

    标签: android deep-linking intentfilter


    【解决方案1】:

    我唯一的想法是添加一个意图过滤器,如果设备打开一个特殊的 URL(例如 www.your-project.com),它会启动您的应用程序。看看这个 documentation 它解释了与您的应用相关的所有社交网站。

    如果用户安装了您的应用,点击链接将打开您的应用。否则链接将被您的默认浏览器打开。

    【讨论】:

      【解决方案2】:

      您想要实现的只能在 Android 6.0 中实现,在 Android 6.0 中,您可以绕过 Intent 选择器对话框并在单击链接时直接启动您的应用程序。

      为此,请查看此App link 文档。他们已经很好地解释了如何做到这一点

      您可能还需要通过添加参数android:autoVerify="true" 对意图过滤器进行如下所示的轻微修改

      <activity ...>
      
      <intent-filter android:autoVerify="true">
          <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="www.example.com" />
          <data android:scheme="https" />
      </intent-filter>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-16
        • 1970-01-01
        • 2020-11-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多