【问题标题】:Intent.toUri(0): in Reverse OrderIntent.toUri(0):以相反的顺序
【发布时间】:2017-01-07 17:16:41
【问题描述】:

我们可以简单地将Intent 对象转换为Uri 对象:

Intent intent = ...;
Uri uri = intent.toUri(Intent.URI_INTENT_SCHEME);  // The value of flag is not important for me.

如何以相反的顺序进行?


我的知识

有一个静态方法获取String 作为它的参数。 (当然,它已被弃用。)

Intent.getIntent(String uri);

还有两个接受Uri的构造函数,但它们也接受其他我不知道它们的值的参数:

1) Intent(String action, Uri uri);
2) Intent(String action, Uri uri, Context packageContext, Class<?> cls)

我只有一个uri 和传递给toUri(int flags)flags 参数的值。


其他信息

实际上,我有一个来自shouldOverrideUrlLoading(WebView view, WebResourceRequest request)WebResourceRequest 对象(属于WebViewClient 类)。

不注意弃用不会有任何问题。因为下面的方法实际上很好用:

@SuppressWarnings("deprecation")
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Intent intent = Intent.getIntent(url);
    ...
}

shouldOverrideUrlLoading(WebView, String)Intent.getIntent(String) 都已被弃用。

【问题讨论】:

    标签: android android-intent uri


    【解决方案1】:

    Use parseUri()。引用文档:

    从 URI 创建意图。如果由 toUri(int) 返回,则此 URI 可以对操作、类别和其他意图字段进行编码。如果 Intent 不是由 toUri() 生成的,则其数据将是整个 URI,其操作将为 ACTION_VIEW。

    【讨论】:

    • 你的意思是Intent.parseUri(request.getUrl().toString(), flags)?我会尽快测试并报告结果。
    猜你喜欢
    • 2023-03-31
    • 1970-01-01
    • 2016-09-20
    • 2015-02-17
    • 1970-01-01
    • 2016-10-05
    • 2011-11-02
    • 2019-03-28
    • 1970-01-01
    相关资源
    最近更新 更多