当前位置: 首页 > 知识库问答 >
问题:

Android应用程序索引和深度链接:我一直都搞错了吗?

程举
2023-03-14

我正在实施应用程序索引,我想我遗漏了一些东西,但我不知道是什么。

按照指南,我在应用程序中添加了我的意图过滤器,并实现了活动中需要的内容。

我的应用程序包是com。塔。hotelsclick和相关html" target="_blank">网站(由于我只是测试,我还没有在那里放置link rel meta标签)是www.hotelsclick。通用域名格式

我在指南中看到了下面的意图过滤器示例

<activity
  android:name="com.example.android.PetstoreActivity"
 android:label="@string/title_petstore">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <catehtml" target="_blank">gory android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" />
        <data android:scheme="https" />
        <data android:host="www.examplepetstore.com" />
    </intent-filter>
</activity>

所以我这样写我的:

    <activity
        android:name=".ActivityForAppIndexing"
        android:label="@string/title_activity"
        android:screenOrientation="portrait" >
        <intent-filter android:label="@string/app_name">
            <data android:scheme="android-app"
                android:host="com.package.myappname" />
            <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.mywebsite.com" />
            <data android:scheme="https"
                android:host="www.mywebsite.com" />
        </intent-filter>
    </activity>

另外,我写了一个内容提供程序来解析URI

    <provider
        android:name=".contentproviders.HotelDetailsContentProvider"
        android:authorities="com.towers.hotelsclick" >
    </provider>

应将URI映射如下:

    private static final String BASE_PATH = "https";
private static final String AUTHORITY = "com.towers.hotelsclick";

public static final Uri CONTENT_URI = Uri.parse("android-app://" + AUTHORITY
        + "/" + BASE_PATH);

我正在使用以下adb命令通过命令行测试实现:

adb shell am start -a android.intent.action.VIEW -d "https://hotelsclick.com?hotel_id=135738" com.towers.hotelsclick

而且很有效。应用程序会自动打开,并使用正确的活动和参数。当应用程序启动时,将调用onNewIntent方法:

    protected void onNewIntent(Intent intent) {
    String action = intent.getAction();
    String data = intent.getDataString();
    if (Intent.ACTION_VIEW.equals(action) && data != null) {
        String recipeId = data.substring(data.lastIndexOf("/") + 1);
        Uri contentUri = HotelDetailsContentProvider.CONTENT_URI.buildUpon()
                .appendPath(recipeId).build();
        bundle = new Bundle();
        bundle.putString("pictureUrl", "");

        //showRecipe(contentUri);
    }
}

(我当然是从例子中得到的,这就是为什么它谈论的是食谱而不是酒店)

但是我想知道:我该怎么办?从意图中获取数据

getIntent().getData().getQuery()

或者使用ContentProvider并从URI获取它们?

另外,如果一切正常,我想用谷歌搜索控制台和“以谷歌的方式查看”功能进行测试。我上传了我的APK,看到一个URI被请求。

现在,在文档的“测试你的应用”部分,我看到了如下链接:http://hotelsclick.com?hotel_id=135738被称为“深度链接”,而像android这样的-app://com.towers.hotelsclick/https/hotelsclick.com?hotel_id=135738被称为“URI”。我说得对吗?

“以谷歌方式查看”的功能要求一个URI,但我不知道如何创建一个。此外,我想知道这个URI是如何传递给应用程序的,我很确定我对这个所有URI/深度链接的东西感到非常困惑,在留档中找不到缓解。

我应该在何时何地使用URI?我应该在何时何地使用deepLink?我猜既然我要把rel=URI链接放在我的网页中,那么应用程序将在应用程序中被调用,并用URI而不是页面的URL进行索引。但如果是这样的话。。。为什么adb shell am start是Android系统。意图行动VIEW-d命令用于测试URL而不是URI?我的应用程序应该能够获取和处理URI或URL吗?怎么做?

我本以为我对应用程序索引有所了解,但今天我开始觉得我一开始就错了。这就是为什么我请求您帮助回答上述问题,并可能为所有这些URL/URI/intent filter/ContentProvider混乱提供帮助。

谢谢大家

共有1个答案

暨宸
2023-03-14

首先,确保应用程序正确处理URL:

adb shell am start \
  -a android.intent.action.VIEW \
  -d 'https://www.hotelsclick.com?hotel_id=135738'

同时检查活动是否可以使用可浏览类别打开:

adb shell am start \
  -a android.intent.action.VIEW \
  -c android.intent.category.BROWSABLE
  -d 'https://www.hotelsclick.com?hotel_id=135738'

如果这不起作用,请编辑您的意图过滤器,使其同时具有类别默认值和可浏览性,如下所示

<activity
  android:name="com.towers.hotelsclick.HotelActivity"
  android:label="@string/app_name">
    <intent-filter>
        <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" />
        <data android:scheme="https" />
        <data android:host="www. hotelsclick.com" />
    </intent-filter>
</activity>

检查android应用程序链接是否被正确处理(无需操作),在手机上打开android-app://com.towers.hotelsclick/https/www.hotelsclick.com?hotel_id=135738

如果这工作唯一的事情你必须做的是添加在您的超文本标记语言页面

<link rel="alternate"
      href="android-app://com.towers.hotelsclick/https/www.hotelsclick.com?hotel_id=135738" />

这告诉谷歌,该页面可以在由com.towers.hotelsclick标识的应用程序中打开,以便查看https://www.hotelsclick.com/?hotel_id=135738(您刚刚测试过的内容)。

 类似资料:
  • 我正在创建一个意图过滤器,以便在我的应用程序URL中进行过滤,如https://www.hotelsclick.com/?hotel_id=135738 我在文档中看到,我应该创建一个意图过滤器,比如 这个意图过滤器应该过滤URL,比如“http://example.com/gizmos?1234, http://example.com/gizmos/1234, http://example.co

  • 我想创建一个深层链接,当用户按下一个共享按钮,我分享这样的链接-(例如网址)https://www.myapp.com/Home_page(我已经购买了一个域,我的应用程序也可以在播放商店),并希望当用户点击此链接时,他们应该重定向到我的应用程序的Home_page活动,但当我点击页面未找到显示。 我的舱单代码是:- 现在我不明白该怎么办

  • 我有一个网站可以让用户进行搜索查询。查询可能需要一些时间来完成(几分钟到几天),我想让用户下载一个Android应用程序,并通过向用户发送一封带有链接的电子邮件来收到答案。 我希望无论用户是否安装了应用程序,这种机制都能起作用;换句话说: 如果用户拥有该应用程序,则应该使用包含标识符参数的深层链接打开该应用程序。 如果用户没有它,它应该在应用程序的页面上打开播放商店(例如

  • 我想为我的cordova android应用程序启用应用程序索引,如下所述:https://developers.google.com/app-indexing/webmasters/app 不幸的是,我找不到留档如何做一个科尔多瓦的应用程序。有一个插件收听和广播意向,但我不认为这将帮助我在这种情况下:https://github.com/Initsogar/cordova-webintent 我

  • 因此,我试图找出是否有可能深度链接当前未安装该应用程序的用户。以下是我试图做的:1)用户在移动浏览器中点击网站上的深度链接。2) 用户将被带到应用商店安装应用3)一旦安装,用户将被带到应用中特定内容的深层链接。 到目前为止,我发现的最接近Android应用程序安装横幅的东西,但这并不是我想要的。这可能吗? 以下是页面底部附近Android应用安装横幅的链接:https://medium.com/@

  • 我在Android上使用了一个用Ionic构建的应用程序中的deep link。当我点击链接时,应用程序打开了,但仅仅一秒钟后就崩溃了。如何调试此问题? 这是AndroidManifest.xml中的意图代码: 更新 通过使用Android Studio,我有以下日志: