WebViewExtra

an extension for AI2 that extends the features of the native webviewer


INTRO:

The extension, by default, will provide the following features:


FEATURES:

Uploading Files

Many websites provide a method to upload files to their server for a variety of reasons. This is usually achieved through html/css/javascript/php/(other) using a form and the input tag with the file attribute and another input tag using the submit attribute. An example of this can be found here

The extension provides a file filtering option, using file mimetypes, in order to limit the available files offered for upload. Files that are not available are usually still visible, but greyed out/ or non-selectable. It should be possible to browse all the shared directories and select files.

In testing it was found that you can also upload files to Google Drive using a Google Form upload section.

Resources:

HTML file that provides an upload form (uploads to a google drive folder)

Link to Google drive folder: WVEUploadDemo

Downloading Files

Files are saved to the shared Download directory on the device.

It should be possible to download files from any download link with a filename at the end, but will also work where the filename is obfuscated by the website, e.g. Google Drive, or the AI2 community.

It is possible to browse a shared google drive folder, and download a file from there (you may need to be signed into a google account for this to work)

Resources:

HTML file which contains some example links

Link to Google Drive folder: WVEDownloadDemo

Modifed UserAgent

Here, we remove the `: wv` from the existing userAgent, helping to fool Google and other sites to believing that the webviewer is not an embedded webview.


Update 06/09/2023

It seems that simply removing ; wv from the default useragentstring is now not enough, and we also need to remove Version/4.0 and Mobile . Also, not all android devices present the same webview useragentString, e.g. Samsung, Asus, Redmi, Motorola..., therefore it may be necessary to modify the useragent presented in those webviews, hence the provision of the get and set useragent blocks. A useful link for native browser user agents: Device Atlas.


Here is a simple web app that helps to demonstrate the benefit of the modified userAgent. You can test this in a standard webviewer and one with the extension to see the difference. You must be logged into your google account inside the webviewer. The webviewer will remember your login for subsequent use. Here also are two useful urls for loggin in and signing out of Google.

https://accounts.google.com/ServiceLogin

https://accounts.google.com/Logout

Copy the url below, which is a simple webapp that requires a google account user to authenticate the web app to access the google account. The webapp itself, using the url below, will do nothing other than return a text message to the webviewer if authorisation has worked. If you follow the authentication through, you can revoke access in your Google Account/Security/Third Party Apps.

https://script.google.com/macros/s/AKfycbz23Ho3obdqVTmxrSuu8E-hsv8PlKoTh6cCGOcfeIuLB-dzl9O-ol_wwFct1fad31Ci/exec?FN=authenticate


This modification may not have the desired effect in all settings....

Allow File Access

Provides the webviewer with access to the file system. Several of the other features will require this.

Set READ & WRITE EXTERNAL STORAGE permissions for app

The following permissions are set in the manifest file of the extension:

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

This will enable some of the features to access files, but also, enable the app, with the correct filescope settings, to copy files from the ASD to a shared directory, making them available for uploading. Also added are the new MEDIA permissions required by the Sep 2023 update to Android.

localStorage and sessionStorage

The localStorage object allows you to save key/value pairs in the browser.

Resources:

HTML file that demonstrates that localStorage works with the webviewer

Zoom Controls

This setting turns zoom features on or off

BLOCKS

Basic setup

FILES

AIX

WebViewExtra

RESOURCES/CREDITS

This extension was created following extensive research carried out on StackOverflow, Android Developers, Youtube, and many other internet sites providing java/android solutions to the issues raised in putting it together. Hundreds of topics and web pages eventually provided all the answers.

A special mention to Sunny Gupta(vknow360) and Luke Gackle, whose open sourced extensions provided some of the groundwork.

ADDENDUM

With the arrival of new features in the 1.7 release for accessing files in the ASD, the workaround below is no longer neccessary, I leave it here for posterity...



 Blocks to provide Files in ASD for upload

First up you need to set the default filescope to Legacy in Screen1 properties.

You will need the File component.

Also bear in mind that the extension needs to be in place and loaded to the webviewer, this will set the required read and write external storage permissions for the app.

 This will not work unless you make these settings.

You need to create a directory in the Shared Folders for the ASD files. In this example, the directory is created in /Documents

Then you can copy all the files in your ASD to the folder you have created

When you have finished uploading files from your Shared ASD folder, you can, if you wish, delete all the files there.