如何深入地提供意图数据 Link
How to give Intent Data in Deep Link
我更新了清单文件以支持深度 linking。我已经从 运行(Edit Configuration) 中检查过它,它会打开指定的 activity.
现在我需要用深度 link 发送一些数据。那么它的程序应该是什么。我添加了另一个数据属性,但我不明白如何以相同的 key/value 方式在 Activity 中获取数据。
我在 Activity
中得到这样的 Intent
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
intent.getData() has this value= myapp://videodeeplink
我已经阅读了一些关于此的文章和教程,但我就是无法理解。请指导我如何在深度 linking 中放置和获取一些数据。
myapp://videodeeplink
<activity
android:name=".VideosListActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="myapp" android:host="videodeeplink"/>
<data android:scheme="videoURL" android:host="videoURL"/>
</intent-filter>
</activity>
要发送数据,您应该在数据标记中添加 pathPrefix 参数,如下所示,以便稍后我们可以在您调用它的 Activity/Fragment 中解析它。
<data
android:host="@string/host"
android:pathPrefix="path"
android:scheme="@string/schema" />
现在当你想解析它时,你可以使用 Android 中的 pathSegments,就像下面使用 intents 来获取里面的数据。
mainIntent = getIntent();
if (mainIntent!=null && mainIntent.getData()!=null
&& (mainIntent.getData().getScheme().equals("http"))){
Uri data = mainIntent.getData();
List<String> pathSegments = data.getPathSegments();
if(pathSegments.size()>0)
String prefix=pathSegments.get(0); // This will give you prefix as path
}
我更新了清单文件以支持深度 linking。我已经从 运行(Edit Configuration) 中检查过它,它会打开指定的 activity.
现在我需要用深度 link 发送一些数据。那么它的程序应该是什么。我添加了另一个数据属性,但我不明白如何以相同的 key/value 方式在 Activity 中获取数据。
我在 Activity
中得到这样的 Intent Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
intent.getData() has this value= myapp://videodeeplink
我已经阅读了一些关于此的文章和教程,但我就是无法理解。请指导我如何在深度 linking 中放置和获取一些数据。
myapp://videodeeplink
<activity
android:name=".VideosListActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="myapp" android:host="videodeeplink"/>
<data android:scheme="videoURL" android:host="videoURL"/>
</intent-filter>
</activity>
要发送数据,您应该在数据标记中添加 pathPrefix 参数,如下所示,以便稍后我们可以在您调用它的 Activity/Fragment 中解析它。
<data
android:host="@string/host"
android:pathPrefix="path"
android:scheme="@string/schema" />
现在当你想解析它时,你可以使用 Android 中的 pathSegments,就像下面使用 intents 来获取里面的数据。
mainIntent = getIntent();
if (mainIntent!=null && mainIntent.getData()!=null
&& (mainIntent.getData().getScheme().equals("http"))){
Uri data = mainIntent.getData();
List<String> pathSegments = data.getPathSegments();
if(pathSegments.size()>0)
String prefix=pathSegments.get(0); // This will give you prefix as path
}