Android 如何使用 java 从 android 中的深层 link 获取值?
Android How to get values from deep link in android using java?
Android 如何使用 java 从 android 中的深层 link 获取值?
我在我的 android 应用程序中实现了深度 link,现在我想获取所有参数,如斜杠后的所有参数。
我的 url = www.exmple.com/poduct-name/prodcut_id
www.exmple.com/iphone/147895
所以我想从上面获取 id-147895 url?
试试这个--
URI uri = new URI("www.exmple.com/iphone/147895");
String[] spPath= uri.getPath().split("/");
String idStr = spPath[spPath.length-1];
int id = Integer.parseInt(idStr);
谢谢你
对于您想要开始深度链接处理的 activity
,将此 Intent 过滤器放入清单中的 <activity>...</activity>
中,如下所示:
<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:host="www.example.com"
android:pathPattern="/.*"
android:scheme="https"/>
</intent-filter>
然后在你的 activity 中,如果它被标记为 "singleTask" 你将能够从意图中获取数据,在 onNewIntent(Intent intent)
方法中,或者如果它被标记为 "newTask" 你应该在 onCreate(...)
中调用你的解析方法,并通过调用 getIntent()
方法来获取意图。解析过程将是这样的,
1. 对于 onCreate():
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.your_view);
if (getIntent() != null && getIntent().getData() != null)
{
//parse your data here,
//it's the deeplink you want "https://www.example.com/..."
}
}
对于 newIntent()
protected void onNewIntent(Intent 意图)
{
super.onNewIntent(意图);
如果(意图!= null && intent.getData()!= null)
{
//在这里解析你的数据,
//这是你想要的深层链接“https://www.example.com/...”
}
}
Android 如何使用 java 从 android 中的深层 link 获取值? 我在我的 android 应用程序中实现了深度 link,现在我想获取所有参数,如斜杠后的所有参数。 我的 url = www.exmple.com/poduct-name/prodcut_id
www.exmple.com/iphone/147895
所以我想从上面获取 id-147895 url?
试试这个--
URI uri = new URI("www.exmple.com/iphone/147895");
String[] spPath= uri.getPath().split("/");
String idStr = spPath[spPath.length-1];
int id = Integer.parseInt(idStr);
谢谢你
对于您想要开始深度链接处理的 activity
,将此 Intent 过滤器放入清单中的 <activity>...</activity>
中,如下所示:
<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:host="www.example.com"
android:pathPattern="/.*"
android:scheme="https"/>
</intent-filter>
然后在你的 activity 中,如果它被标记为 "singleTask" 你将能够从意图中获取数据,在 onNewIntent(Intent intent)
方法中,或者如果它被标记为 "newTask" 你应该在 onCreate(...)
中调用你的解析方法,并通过调用 getIntent()
方法来获取意图。解析过程将是这样的,
1. 对于 onCreate():
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.your_view);
if (getIntent() != null && getIntent().getData() != null)
{
//parse your data here,
//it's the deeplink you want "https://www.example.com/..."
}
}
对于 newIntent()
protected void onNewIntent(Intent 意图) { super.onNewIntent(意图); 如果(意图!= null && intent.getData()!= null) { //在这里解析你的数据, //这是你想要的深层链接“https://www.example.com/...” } }