【问题标题】:Android App Indexing - > FirebaseAppIndexingInvalidArgumentExceptionAndroid 应用索引 - > FirebaseAppIndexingInvalidArgumentException
【发布时间】:2017-04-30 03:04:22
【问题描述】:

嘿嘿!

我正在尝试实现应用索引内容,并从app-indexing Google codelabs 示例开始。

运行此代码

 Indexable recipeToIndex = new Indexable.Builder()
           .setName(mRecipe.getTitle())
           .setUrl(mRecipe.getRecipeUrl())
           .setImage(mRecipe.getPhoto())
           .setDescription(mRecipe.getDescription())
           .build();

 FirebaseAppIndex.getInstance().update(recipeToIndex); 

总是导致update() 方法抛出FirebaseAppIndexingInvalidArgumentException

com.google.firebase.appindexing.FirebaseAppIndexingInvalidArgumentException: Intent 'Intent { act=android.intent.action.VIEW dat=http://example.com pkg=com.example }' cannot be resolved. The invalid indexable is: Indexable { { id: 'http://example.com/123' } Properties { { key: 'name' value: [ 'test_name' ] } } Metadata { worksOffline: false, score: 0 } }
                          at com.google.firebase.appindexing.internal.zzn.zzb(Unknown Source)
                          at com.google.firebase.appindexing.internal.zzd$zzc$1.onComplete(Unknown Source)
                          at com.google.android.gms.tasks.zzc$1.run(Unknown Source)
                          at android.os.Handler.handleCallback(Handler.java:739)
                          at android.os.Handler.dispatchMessage(Handler.java:95)
                          at android.os.Looper.loop(Looper.java:145)
                          at android.app.ActivityThread.main(ActivityThread.java:5951)
                          at java.lang.reflect.Method.invoke(Native Method)
                          at java.lang.reflect.Method.invoke(Method.java:372)
                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

您对如何将图像添加到Indexable 有什么建议吗?

【问题讨论】:

  • 你想将什么传递给 .setImage 函数?它必须是这样的照片 url:“example.com/salad.jpg”此外,提供的堆栈跟踪看起来很奇怪......该代码实验室没有索引任何形式为 example.com/123 的东西——这是你自己写的吗?
  • 你能找到分辨率吗,我也遇到了同样的异常。我没有传递图片网址,这是强制性的吗?

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


【解决方案1】:

我收到此错误的原因是我正在测试的应用的清单中没有意图过滤器。

确保您在 indexable 上设置的 url 在清单中有匹配的条目

    <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter android:label="@string/app_name" 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="century.com"
                    android:pathPrefix="/recipe" />
            </intent-filter>
        </activity>

【讨论】:

    【解决方案2】:

    像这样删除图片消息或编辑代码。

    if (friendlyMessage.getText() != null) {
       FirebaseAppIndex.getInstance().update(getMessageIndexable(friendlyMessage));
    }
    FirebaseUserActions.getInstance().end(getMessageViewAction(friendlyMessage));
    

    似乎教程没有考虑没有消息的消息。所有消息都应该是文本或带有图像的文本。要修复它,您应该检查。 https://github.com/firebase/friendlychat/issues/160

    【讨论】:

    • 我遇到的问题与 OP 略有不同。我在 setName 函数上得到了 NPE,因为其中一条消息只是一个图像并且没有文本。空检查有帮助。
    【解决方案3】:

    确保 setUrl() 收到格式正确的 URL,我的 URL 是 http://app.com//path

    //之前的路径导致了问题

      Indexable recipeToIndex = new Indexable.Builder()
               .setName(mRecipe.getTitle())
               .setUrl(Uri.parse(mRecipe.getRecipeUrl()).toString())
               .setImage(Uri.parse(mRecipe.getPhoto()).toString())
               .setDescription(mRecipe.getDescription())
               .build();
    

    这对 setImage 来说不是那么重要

    【讨论】:

      【解决方案4】:

      您应该从Indexables 类中选择合适的(或更适合的)生成器,如示例中所示。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多