为什么WebChromeClient openFileChooser从文档隐藏?它是安全使用这种方法吗? [英] Why openFileChooser in WebChromeClient is hidden from the docs? Is it safe to use this method?

查看:628
本文介绍了为什么WebChromeClient openFileChooser从文档隐藏?它是安全使用这种方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数我看到的地方,文件上传功能在的WebView的使用 openFileChooser()方法的实现。它是法律/安全地使用这种方法吗?如果我用这个在code,我的code随时随地打破?任何安全问题,如果我用这个方法?

Most of the places I see, file upload feature in WebView is implemented using openFileChooser() method. Is it legal/safe to use this method? If I use this in code, will my code break anywhere? Any security issues if I use this method?

为什么Android的隐藏这个API在旧版本?只有在/ 5.0以上,他们纷纷推出onShowFileChooser()方法,这意味着官方不支持文件上传在5.0以下网页视图?

Why android hides this API in older versions? Only on/above 5.0 they have introduced onShowFileChooser() method, that means officially they don't support file upload in webviews below 5.0?

推荐答案

使用旧的 openFileChooser(...)回调做的的有任何安全隐患。这只是罚款。唯一的缺点是,它无法在某些平台级别被调用,因此无法正常工作。

Using the old openFileChooser(...) callbacks does not have any security implications. It's just fine. The only downside is that it will not be called on some platform levels and therefore not work.


  • 无效openFileChooser(ValueCallback<乌里> uploadMsg)适用于Android 2.2(API级别8)达至Android 2.3(API等级10)

  • openFileChooser(ValueCallback<乌里> uploadMsg,字符串acceptType)在Android 3.0(API级别11)的作品最多的Andr​​oid 4.0(API级别15)

  • openFileChooser(ValueCallback<乌里> uploadMsg,字符串acceptType,字符串捕获)适用于Android 4.1(API级别16)到Android 4.3的(API级别18)

  • onShowFileChooser(的WebView web视图,ValueCallback<乌里[]> filePathCallback,WebChromeClient.FileChooserParams fileChooserParams)适用于Android 5.0(API级别21)和上述

  • void openFileChooser(ValueCallback<Uri> uploadMsg) works on Android 2.2 (API level 8) up to Android 2.3 (API level 10)
  • openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) works on Android 3.0 (API level 11) up to Android 4.0 (API level 15)
  • openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) works on Android 4.1 (API level 16) up to Android 4.3 (API level 18)
  • onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) works on Android 5.0 (API level 21) and above

您可以使用这个抽象路程,负责所有这些回调对不同的平台上水平,使它只是工作的图书馆。例如:

You can use a library that abstracts this away and takes care of all these callbacks on different platform levels so that it just works. Example:

https://github.com/delight-im/Android-AdvancedWebView

您也可以看看它是如何在源完成的:

You can also check out how it's done in the source:

<一个href=\"https://github.com/delight-im/Android-AdvancedWebView/blob/0f06e73ecee13ebc4552ac00bc0848e18662a25d/Source/src/im/delight/android/webview/AdvancedWebView.java#L597\" rel=\"nofollow\">https://github.com/delight-im/Android-AdvancedWebView/blob/0f06e73ecee13ebc4552ac00bc0848e18662a25d/Source/src/im/delight/android/webview/AdvancedWebView.java#L597

<一个href=\"https://github.com/delight-im/Android-AdvancedWebView/blob/0f06e73ecee13ebc4552ac00bc0848e18662a25d/Source/src/im/delight/android/webview/AdvancedWebView.java#L1044\" rel=\"nofollow\">https://github.com/delight-im/Android-AdvancedWebView/blob/0f06e73ecee13ebc4552ac00bc0848e18662a25d/Source/src/im/delight/android/webview/AdvancedWebView.java#L1044

这是它的无证的事实只是意味着你不能依赖它。当它在Android 2.2的推出,没有人能知道它会停在Android 4.4系统的工作,但你不得不接受它。

The fact that it's undocumented just means that you can't rely on it. When it was introduced in Android 2.2, nobody could know that it would stop working in Android 4.4, but you had to accept it.

这篇关于为什么WebChromeClient openFileChooser从文档隐藏?它是安全使用这种方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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