Android 从浏览器获取 url [英] Android get url from browser

查看:55
本文介绍了Android 从浏览器获取 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am try to open my app on url click and get value from it, url looks like : 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>

但是

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

返回: param is:item/item .如何获取键=值或完整网址

returns: param is:item /item . how to get key=value or full url

推荐答案

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

This is how I did recently in my app

使用以下意图过滤器

<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>

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

In your URL use following

适用于 Chrome

for Chrome

window.location = "intent://item?key=value#Intent;scheme=<SCHEME_NAME>;package=<APP_PACKAGE>;";`

其他弓箭手

window.location = "<SCHEME_NAME>://item?key=value";

在 Activity 类中使​​用以下内容

In the Activity class use following

String uriPath = getIntent().getDataString();

uriPath 将包含字符串item?key=value",您可以根据模式对其进行解析.

uriPath will have string "item?key=value" which you can parse based on patterns.

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

You can Modify the "item?key=value" in your JS to send only value if required. Do experiment on this.

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

这篇关于Android 从浏览器获取 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆