Android – WebView – the best way to upload images from your device

I currently have applications on Google play and iTunes, which are the native packaging of shared WebView. The beauty of WebView is that I can make changes on the WebView side and view them immediately on any device, but the problem I encounter is that I can upload images from user Albums / galleries stored on their devices

If yes, using my current WebView strategy, allow users to upload images from their device's native album / gallery. What is the fastest implementation?

resolvent:

You can use standard file input types:

<form action="/server/upload" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

This should be used out of the box on IOS 6 and open the native open file dialog box, but you must code it on Android

There is a solution using unofficial API (webchromeclient #openfilechooser) on olders platform, but Google broke this in KitKat, and then released official support for this function using webchromeclient.html#onshowfilechooser in lollipop. Therefore, KitKat may continue to be damaged, but it should work normally on other platforms

See this Android error report problem 62220

You can implement it yourself (see this example), but if you are looking for a "working" WebView subclass, you may need to try the Android advanced WebView project

Another option, or just as a fix to the KitKat device, is to have the native wrapper encode the file as Base64 string, and then the HTML application can send it to the server

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>