用于友好 URL 的 Android 深层链接

问题描述

清单中的深层链接将如何使用此链接打开活动

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" />

解决方法

在清单文件中的活动标签中试试这个

<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)) );
 }
,

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

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

在我的活动中:

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...