Android Webview Texture

February 1, 2017

{:.no_toc}

This project is ARCHIVED, support is over, it has been removed from the Asset Store.
If you want to know more about why, I wrote about it here

Pitch

✨ This is a working Webview Texture for Android ✨
It also has been tested in VR ✅ and works well with both Google Cardboard SDK, Google Daydream SDK and GearVR.

It is very fast because unlike some plugins this is a GL texture and not a bitmap copy of the view.

Screenshots/videos

Screenshot (3D texture)

This Webview will act like a standard texture, usage are limit-less:

Video (VR mode)

I want to thank Oculus that open sourced a part of their SDK and it has been a great source of inspiration for me, also want to thank Felix Jones who help me to get things right.

Documentation

Limitations

This plugin requires Android Kitkat 4.4 (API 19) or more.
It will only work with arm64 devices!

⚠️ It has some limitations (but I'm working on it)

  • You can only have one VR Webview on your scene
  • It works only for Android (no preview available on the Unity Editor) not working on iOS,
  • The Webview itself is not hardware accelerated — read this it is important — it means that no WebGL websites will work, and more important, most video won't play (because they often use hardware rendering to play) and <canvas> won't be hardware accelerated
  • Android API >= 19

I am sorry about these limitations.

VR Configuration

Tested with Google Daydream and Google Cardboard
other VR SDK could work, but there is no guarantee.

You must have a Google VR Unity version (-GVRXX) or use the last Unity beta (5.6)
Your build parameters (found in Build Settings > Player Settings) should look like this:

Events mechanism

The Webview will give you delegate messages for specific events:

  • onPageStarted:string → when a new url is about to be loaded
  • onPageFinished:string → when a new url has finished to load
  • onReceivedError:string → when an error happen
  • onResultEvaluateJavascript:string → result of a EvaluateJavascript call

you can parse these messages and handle it as you wish

Of course, you can send touch event to the Webview, this will allow you to click links, scroll the view and much more.
➡️ A full working example is included.

Download

Download link has been removed.

Note that the JAVA part of the source code is included in the asset.
The included source code is licensed under the MIT license.

Copyright (c) 2017 Jérôme Gangneux

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.