首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android Deep Link:如何在清单中使用intent-filters打开不同的活动?

Android Deep Link:如何在清单中使用intent-filters打开不同的活动?
EN

Stack Overflow用户
提问于 2017-09-19 16:40:04
回答 1查看 1.2K关注 0票数 1

我有3个网址的设置意图过滤器

-> https://www.example.com ->打开活动A

代码语言:javascript
复制
<intent-filter>
                <data android:scheme="Appname" />
                <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.example.com"
                    android:pathPrefix="/^/?$"
                    android:scheme="https" />
</intent-filter>

-> https://www.example.com/internships或-> https://www.example.com/internships/打开活动B

代码语言:javascript
复制
<intent-filter android:label="Awign">
                <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.example.com"
                    android:pathPattern="/internships^/?$"
                    android:scheme="https" />
</intent-filter>

-> https://www.example.com/internships/{some_path_param} ->打开活动C

代码语言:javascript
复制
<intent-filter>
                <data android:scheme="Appname" />
                <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.example.com"
                    android:pathPrefix="/^/?$"
                    android:scheme="https" />
</intent-filter>

活动A和C如期打开,我如何才能实现活动B的预期结果?

另外,如何在chrome浏览器搜索中允许深度链接?例如,如果我在搜索结果中有这三个URL。我说的不是在地址栏中输入URL,而是搜索结果。正如在其他问题中提到的,在地址栏中键入结果无论如何都不会打开应用程序

EN

回答 1

Stack Overflow用户

发布于 2017-09-20 00:10:47

使用Branch's deep linking SDK,您应该能够通过添加$deeplink_path来简化此过程。这将允许您在不依赖正则表达式的情况下处理深度活动。

要进行此设置,您的清单只需包含以下内容:

代码语言:javascript
复制
   <activity android:name="com.yourapp.your_activity">
         <!-- App Link your activity to Branch links-->
         <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="https" android:host="yourapp-alternate.app.link" />
            <data android:scheme="https" android:host="yourapp.app.link" />
         </intent-filter>
    </activity>

然后,为了处理这个链接,你应该有这样的东西:

代码语言:javascript
复制
Branch branch = Branch.getInstance(getApplicationContext());
branch.initSession(new BranchReferralInitListener(){
    @Override
    public void onInitFinished(JSONObject referringParams, BranchError error) {
        if (error == null) {
            // params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
            // params will be empty if no data found
            // ... insert custom logic here ...
        } else {
            Log.i("MyApp", error.getMessage());
        }
    }
}, this.getIntent().getData(), this);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46295735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档