【问题标题】:Is it possible to add extras to browsable intents from HTML是否可以从 HTML 向可浏览的意图添加额外内容
【发布时间】:2016-08-08 14:36:52
【问题描述】:

让我们来看看下面的清单:

<intent-filter>
    <data scheme="myscheme"
          host="myhost">
    </data>
    <action name="android.intent.action.VIEW">
    </action>
    <category name="android.intent.category.DEFAULT">
    </category>
    <category name="android.intent.category.BROWSABLE">
    </category>
</intent-filter>

我可以通过将浏览器重定向到以下位置来启动在上述意图过滤器下声明的活动:

myscheme://myhost?param1=param1&param2=param2

但是,我很难理解是否可以进行相同的重定向,只有通过以下方式以编程方式接收的额外附加内容:

myextra = getIntent().getStringExtra('myextra')

非常感谢任何帮助。

【问题讨论】:

    标签: android extras browsable


    【解决方案1】:

    这就是我克服这个问题的方法,

    我开发了自己的浏览器并像你一样可以浏览

    Uri data = getIntent().getData();
    
    if(data == null) { // Opened with app icon click (without link redirect)
        Toast.makeText(this, "data is null", Toast.LENGTH_LONG).show();
    }
    else { // Opened when a link clicked (with browsable)
        Toast.makeText(this, "data is not null", Toast.LENGTH_LONG).show();
        String scheme = data.getScheme(); // "http"
        String host = data.getHost(); // "twitter.com"
        String link = getActualUrl(host);
        webView.loadUrl(link);
        Toast.makeText(this,"scheme is : "+scheme+" and host is : "+host+ " ",Toast.LENGTH_LONG).show();
    }
    

    我想你正在寻找这个功能

    data.getQueryParameter(String key);

    【讨论】:

    • 查看我对 theFunkyEngineer 的回复了解更多详情。
    【解决方案2】:

    将数据直接从网页传递到您的应用程序的唯一方法是使用您在intent-filter 中注册的 URL。所有都将通过Uri 对象检索——无论数据是在路径上还是带有查询参数,如下所述。无法通过网页在 Intent 上设置额外内容。

    Uri uri = getIntent().getData();
    String param1Value = uri.getQueryParameter("param1");
    

    【讨论】:

    • 其实我说的不是参数。我说的是通过 HTML 重定向发送额外的对象。我想知道是否存在“intent.putExtra('value')”的 HTML 等价物
    • 啊,好的。无法从网页上为 Intent 设置额外内容。更新了我的回复以反映这一点。
    【解决方案3】:

    当通过 javascript 或 HTML 重定向到自定义意图方案 URL 时,可以使用“意图方案 URL”来发送更多信息,例如额外的对象和操作。

    intent://foobar/#Intent;action=myaction1;type=text/plain;S.xyz=123;end
    

    虽然这个方法实际上并没有回答这个问题,因为方案部分注定总是“意图”,但这是一种从浏览器发送带有额外对象或动作的意图的可能方式。

    在以下报告中查看更多详细信息:

    http://www.mbsd.jp/Whitepaper/IntentScheme.pdf

    或者使用 chrome 文档:

    https://developer.chrome.com/multidevice/android/intents

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-14
      • 2016-01-30
      相关资源
      最近更新 更多