【问题标题】:Android Deep link for friendly URLs友好 URL 的 Android 深层链接
【发布时间】:2021-06-17 18:55:21
【问题描述】:

manifest 中的深层链接 将如何使用此链接打开一个活动

https://myapp.domain.com/#/view/abc

其中只有 abc 是变化的 参数,并且是我需要应用程序将其作为 参数 的参数。

我试过了,但是没用

            <data
                android:host="myapp.domain.com"
                android:pathPrefix="/#/view"
                android:scheme="https" />
            <data
                android:host="myapp.domain.com"
                android:pathPrefix="/#/view"
                android:scheme="http" />
            <data
                android:host="myapp.domain.com"
                android:pathPrefix="/#/view"
                android:scheme="app" />

【问题讨论】:

    标签: android android-studio url android-manifest android-deep-link


    【解决方案1】:

    在 Manifest 文件中的 Activity Tag 中试试这个

    <intent-filter android:label="Example">
          <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="myapp.domain.com"
                android:pathPrefix="/#" />
                <!-- note that the leading "/" is required for pathPrefix-->
    </intent-filter>
    

    Activity.java 内部

     Uri uri = getIntent().getData();
     
     if(uri != null){
          List<String> segments = uri.getPathSegments();
          Log.e(TAG, "onCreate: "+segments );
          Log.e(TAG, "onCreate: "+segments.get((segments.size()-1)) );
     }
    

    【讨论】:

    • 不起作用,当点击链接时,android 只显示打开 chrome 而不是我的应用程序:(
    【解决方案2】:

    经过努力,我使用了这个:

    <data android:scheme="https"
            android:host="myapp.domain.com"
            android:pathPrefix="/" />
    

    在我的活动中:

     String id = data.toString().replaceAll(".*/", "");
    

    注意:我不能使用 uri.getPathSegments(); 因为它返回给我一个空列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多