Android从浏览器获取url

标签 android url

我尝试在点击 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/

相关文章:

android - 更改主题时呈现问题

java - com.google.gson.JsonSyntaxException : java. lang.IllegalStateException:应为 BEGIN_ARRAY 但为 STRING

javascript - AJAX URL 中的十进制值

java - Android:如何使用下载管理器类?

Android - 同屏ListFragments

android - 无法为android图形 View 线图生成数据点系列

Android app + MySQL数据库结构与设计

url - 如何在 grails 中使用 POST 重定向到外部 URL

ios - 翠鸟不显示图像

javascript - 使用数组的值更改 div 的背景 url