【问题标题】:How to implement app indexing with library project?如何使用库项目实现应用程序索引?
【发布时间】:2017-03-28 19:52:11
【问题描述】:

我正在尝试为我的一个应用程序实现应用程序索引,但我不太确定我应该为应用程序索引 Action 返回什么 appUri

假设我有一个包名com.example.myappwebUri http://example.com/some/path

据我了解,在这种情况下,appUri 通常是com.example.myapp/http/example.com/some/path,对吗?

现在输入我的应用程序使用的库项目,以及索引活动所在的位置。让我们调用库项目com.example.mylibrary 和索引活动MyActivity

如果我想使用 adb 启动活动,我会使用

adb shell am start -W -a android.intent.action.VIEW -d "http://example.com/some/path" com.example.myapp/com.example.mylibrary.MyActivity

所以,我的问题是 - 在这种情况下,应用程序索引 ActionappUri 应该是什么?活动在图书馆项目中这一事实是否会影响它?

【问题讨论】:

    标签: android android-library android-app-indexing google-app-indexing firebase-app-indexing


    【解决方案1】:

    一般而言,您可以通过库提供的 Action.Builder 来构建 Action。作为 uri,您需要提供相关的 URI。因此,如果您想索引 View Action,您应该提供被查看的产品的 URI。

    Uri.Builder builder = new Uri.Builder();
        String uriStr = builder
            .scheme("http")
            .authority("example.com")
            .appendPath("some/path").build().toString();
    
        Action action = new Action.Builder(Action.Builder.VIEW_ACTION)
            .setObject("productName", uriStr)
            .build();
    


    有关更多详细信息,您可以查看 logging actions docs 及其示例应用程序。
    测试:

    adb shell am start -a android.intent.action.VIEW -d "{URL}" {package name}
    

    其中 {package name} = com.example.myapp 和 URL = http://example.com/some/path

    最后,您放置在库中的 Activity 应该具有可以处理您的 URI http://example.com/some/path 的意图过滤器

    【讨论】:

    • 抱歉,您的adb 命令对我不起作用,我收到了Error: Activity not started, unable to resolve Intent。我相信这是因为活动在图书馆项目中,这就是我首先提出这个问题的原因(请参阅问题中的adb 命令 - 因为它引用了图书馆项目,所以这是有效的)......
    • 我的错 - 原来 URL 周围的引号以某种方式被弄错了那些花哨的引号 (“ ”)!由于某些原因导致Error: Activity not started, unable to resolve Intent 仅使用包名称时,但在指定完整包名称+活动时工作正常。问题解决了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    • 2018-01-25
    相关资源
    最近更新 更多