我尝试在点击 url 时打开我的应用程序并从中获取值(value),url 看起来像:path.com/item?key=value
在 list 中:
<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:host="path.com"
android:pathPrefix="/item"
android:scheme="http" />
</intent-filter>
但是
Uri data = getIntent().getData();
data.getPathSegments();
Log.d("TAG", "param is:" + params.get(0);
返回:参数是:item/item。如何获取 key=value 或完整的 url
最佳答案
这就是我最近在我的应用程序中所做的
使用以下 Intent 过滤器
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="<SCHEME_NAME>" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
在您的网址中使用以下内容
Chrome
window.location = "intent://item?key=value#Intent;scheme=<SCHEME_NAME>;package=<APP_PACKAGE>;";`
其他浏览器
window.location = "<SCHEME_NAME>://item?key=value";
在 Activity 类中使用以下内容
String uriPath = getIntent().getDataString();
uriPath 将包含字符串“item?key=value”,您可以根据模式对其进行解析。
如果需要,您可以修改 JS 中的“item?key=value”以仅发送值。 对此做实验。
点击链接了解更多 https://developer.android.com/training/app-indexing/deep-linking.html
关于Android从浏览器获取url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31205502/