简体   繁体   English

在 Java 中处理来自谷歌助手的深层链接

[英]Handling a deep link from the google assistant in Java

Looking to handle a deep link from the Google Assistant.希望处理来自 Google 助理的深层链接。 As I only have an emulator at the moment I am having trouble testing it (from what I have read it requires a real device).因为我目前只有一个模拟器,所以我在测试它时遇到了麻烦(从我读到的内容来看,它需要一个真实的设备)。 That said, I was wondering if I am handling it the correct way.也就是说,我想知道我是否以正确的方式处理它。 I am unfamiliar with Kotlin and my code was turning into Spaghetti trying to integrate, so I put this together in my existing launcher activity just to try and get it bootstrapped for now.我不熟悉 Kotlin 并且我的代码正在变成意大利面试图集成,所以我把它放在我现有的启动器活动中只是为了尝试让它现在引导。 The manifest and actions.xml were set up like the fitness app tutorial. manifest 和 actions.xml 的设置就像健身应用教程一样。

Am I doing this correctly?我这样做正确吗?

        if (mAuth.getCurrentUser() != null) {
            data = this.getIntent().getData();
            if (data != null && data.isHierarchical()) {
                uriData = data.toString();
                containsStart = containsIgnoreCase(uriData,"start");
                containsRun = containsIgnoreCase(uriData,"run");
                if(containsStart && containsRun) {
                    Intent intent = new Intent(getApplication(), RunActivity.class);
                    intent.putExtra("runStart", true);
                    startActivity(intent);
                }
                }
            else {
                checkUserAccType();
            }
            //Else, if there is no current user, start the Authentication activity
        } 

A few observations and recommendation about your code:关于您的代码的一些观察和建议:

  1. Instead of using containsIgnoreCase uses getPath() and match the path.而不是使用containsIgnoreCase使用getPath()并匹配路径。 See example . 参见示例
  2. Also, for the activity parameter use URL query param instead of containsIgnoreCase .此外,对于活动参数,请使用 URL 查询参数而不是containsIgnoreCase See example 查看示例
  3. Starting the activity or fragment.启动活动或片段。 I assume startActivity and checkUserAccType will handle that part.我假设startActivitycheckUserAccType将处理那部分。 See example . 参见示例
  4. // Else... section should go one line below. // Else... 部分应该在下面一行。
  5. Authentication.验证。 It looks fine.看起来不错。 And it seems you're using Firebase by the getCurrent method signature.看来您正在通过getCurrent方法签名使用 Firebase。 See example 查看示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM