Android 从浏览器获取 url

Ant*_*lev 4 url android

我尝试在 url 单击时打开我的应用程序并从中获取价值,url 看起来像:path.com/item?key=value

在清单中:

<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>
Run Code Online (Sandbox Code Playgroud)

Uri data = getIntent().getData(); 
data.getPathSegments();
Log.d("TAG", "param is:" + params.get(0);
Run Code Online (Sandbox Code Playgroud)

返回: 参数是:item /item 。如何获取键=值或完整网址

Abh*_*agi 5

这就是我最近在我的应用程序中所做的

使用以下意图过滤器

<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>
Run Code Online (Sandbox Code Playgroud)

在您的网址中使用以下内容

window.location = "intent://item?key=value#Intent;scheme=<SCHEME_NAME>;package=<APP_PACKAGE>;";`
Run Code Online (Sandbox Code Playgroud)

其他弓箭手

window.location = "<SCHEME_NAME>://item?key=value";
Run Code Online (Sandbox Code Playgroud)

在 Activity 类中使​​用以下

String uriPath = getIntent().getDataString();
Run Code Online (Sandbox Code Playgroud)

uriPath 将具有字符串“item?key=value”,您可以根据模式对其进行解析。

如果需要,您可以修改 JS 中的“item?key=value”以仅发送值。对此进行实验。

点击链接了解更多 https://developer.android.com/training/app-indexing/deep-linking.html