How to get an Android WebView as a Unity Texture? - android

I spent a week on this already, but I'm not an expert so I may miss something, or even want to do something impossible.
I have a Unity project (with Daydream VR) and my goal is to get a WebView working on a 3D surface (as a texture) in VR mode (for Android)
I know it sounds complicated and, I bet it is.
This is where I am so far:
First of all I started with the samples from Oculus. They made a plugin that links an Android MediaPlayer (native class from android) to a Unity Texture, this is kind of easy because the media player of android already use SurfaceTexture to render itself, and with the plugin they just created a bridge between the two environments.
I got this working easily.
Then after I found this article: http://www.felixjones.co.uk/neo%20website/Android_View/
and so I made a deduction that it could be possible to use the same trick to get a native Android WebView in a Unity Texture.
From the article, I thought that the only thing I needed was a custom Android WebView that renders to a SurfaceView (so it will be quite similar to the Android MediaView) and then the oculus plugin would work too.
Of course nothing was like that...
Step 1/
I made an Android plugin for Unity to expose a custom WebView that (IMHO) would render to a SurfaceView (but I'm not sure it is quite right)
see => JrmgxWebView.java
Step 2/
I compiled the oculus plugin, with minor changes
see => *.cpp
Step 3/
I adapted the Unity script that link both the Android plugin and the oculus plugin for unity, added that to a simple Daydream Scene on a 3D cube (with the script associated)
see => WebviewPlayerSampleWeb.cs
I get logs, and from what I understand, the problem is that the SurfaceView does not get refreshed. I can see that my Custom WebView is instanciated well, most of the code works and there are no error (nor crash)
But the texture only change from white (start value) to black (when the plugin is initialized) and then nothing happen.
The textureId coming from the plugin get stuck to either 0 or 29, and AndroidSurfaceTexture->GetNanoTimeStamp() never returns new values.
On the java side I played with .invalidate(), used .loadUrl() and .loadData() and on the C++ part, I checked each method call to see if everything was called. I spend so much time on this code that I can't even remember all the combination I tried.
What is wrong with this?
I'm sure I'm missing a basic point here.
most code here https://gist.github.com/jrmgx/019cba403769dda27a6d42e48c461b1b
PS: be nice with me, it's been a week, and it is my first time with Unity, C++, JNI and C#
Thank you in advance

Related

Game Object working in scene and game view, but completely invisible in Android build

I have thoroughly searched on the web but I couldn't find anyone with my same problem.
I'm working on a 3D game for Android using Unity. Everything works fine within the editor and on the Unity Remote app, but when I build the project, install it on my smartphone and start it... I can't see a game object.
A screen of the project:
As you can see, the sword is active and visible in the editor, but once I start the actual build I get this:
I can't understand what's wrong, could someone kindly help me? Many thanks.
Does the material of the sword have the standart shader?
If so try one of the mobile ones.
Another idea would be to upgrade to one of the newer p versions of Unity.
Since the sword has a rigidbody, have you enabled gravity and somehow disabled collision and its falling through the ground?
Other than that, it could be a shader problem.
Problem solved. I upgraded from Unity 5.3.2 to 5.3.4, re-built the project and everything works like a charm now.
Sometimes Unity can be... strange.

Using Project Tango Unity example projects

I have tried to use the Project Tango unity examples found here; https://github.com/googlesamples/tango-examples-unity with no success.
I have never used Unity before, and have successfully completed the Codelab: Motion Tracking example fromt he developer resources: https://developers.google.com/project-tango/apis/unity/unity-codelab-motion-tracking.
I downloaded the example files mentioned at the top, open one of the projects (tried several, all have the same problem). Once the project is open, I open the scene that come with it, I go to Build Settings, change platform to Android, change the Bundle Identifier and set the Minimum API Level to Jelly Bean 17 and finally click "Build and Run".
Now it starts to build the project, everything goes fine and the Unity logo shows up on the Tango. And that's it, the Unity logo shows up, no error messages on the computer, but nothing more happens. The program stalls at the Unity logo.
Am I missing some crucial step to get the example projects to actually run?
Thanks in advance!
The example code is Unity 5 based project, so please use the 5.x version of Unity to open it. If you use Unity 4.x version, the scene won't be opened up properly.
However, the code lab is based on Unity 4.6 and it is independent from our sample code. I understand this is a little bit confusing now, we are working on make sure the version are unified.
In short, I would suggest you open our example code with Unity 5.x version. You will be able to run it without a problem.
It was blank empty scene build. thats why after the unity logo it didn't load any scene or do anything.
You need to go to Unity Build Setting and drag and drop all the scenes from the examples folder in it.
Once you have all the scenes. Make sure that AreaDescriptionManagement is on the top of the list.
That is the only step missing from you.
Now, build and run. Everything should be fine.

wrapped android-app crashes on resume "no current context"

i got a webapp build via flambe/haxe which is wrapped by phonegap build to get an .ipa and .apk. For now the only remaining error is that the app looses its context if i switch between apps or pressing home-button resulting in the following error on android:
"W/Adreno200-EGL(31381): <qeglDrvAPI_eglSetBlobCacheFuncsQCOM:5575>: EGL_BAD_PARAMETER"
"E/libEGL(31381): eglSetBlobCacheFuncsANDROID resulted in an error: 0x300c"
"E/SurfaceTexture(31381): [unnamed-31381-1] updateTexImage: invalid current EGLContext"
"E/CanvasTexture(31381): unexpected error: updateTexImage return -38"
The last two lines keep repeating (even after several minutes) until i close the app manually which results in the following error-message:
"E/libEGL(21636): call to OpenGL ES API with no current context (logged once per thread)"
Full errorlog can be viewed here: http://goo.gl/UkxwfI (Dropbox)
One thing that keeps bugging me is the following message since all "related" problems got that feature turned ON, but i cant find anything to change that.
"D/webcoreglue(31381): netstack: Memory Cache feature is OFF"
Another thing is with: D/CordovaActivity(31381): CB-3064: The errorUrl is null
As of http://goo.gl/qZWc4F (github) there seems to be a problem on resuming in cordova. (just strg+f "cb-3064")
Took me the whole day to use google on terms like:
EGL_BAD_PARAMETER, qeglDrvAPI_eglSetBlobCacheFuncsQCOM, SurfaceTexture, CanvasTexture, updateTexImage, invalid current EGLContext, eglSetBlobCacheFuncsANDROID, error: 0x300c, OpenGL ES API
but without any good hints or helpful info.
additional information:
tested on Sony Xperia J (ST26i) and android 4.1.2
min android SDK 14
android:hardwareAccelerated="true" (default since sdk 14)
landscape + fullscreen
webview used to display the website coming from flambe/haxe
used build phonegap / phonegap 3.3 (using 2.8 - 3.3 = same)
building it myself via cordova doesnt help (so it should not relate to phonegap build)
cordova.inappbrowser only used to open links in external browser, website running in webview
website only shows a html5-game (nothing fancy, just something like bejeweld)
Maybe there's some easy help by juggling with the Android-Manifest. I really dont want to do native since the webapp is shipped to iOS via Phonegap too.
Update 1
Tried to reproduce the error using native android and playing with different manifest-settings. But it seems like this has something to do with how phonegap/cordova handles the drawing of everything on screen.
Next things to do will involve posting on phonegap-forums and checking out iOS errorlog. Maybe i find something while comparing my results to: iOS app crashes on resuming
Update 2
iOS-Errorlog doesn't help. Exception Type 20 and Exception Code 8badf00d. Stack shows errors with graphics too (like in android). Errorlog see Link in Comment...
"Fixed" by building android and ios myself with cordova. Resuming/Restarting feels a bit bumpy but thats the next thing to fix.
Phonegap build just doesn't like the life cycle of apps.

Android camera update callback is not called in >4.1.2

I'm working with different version of Android in an application using JNI. I followed This tutorial
First of all, I manage the camera from Java, and send the data using JNI and store it into a OpenCV matrix and then manipulate the data. My application works fine in versions before 4.1.2, but in newest devices, it doesn't work.
The problem is, I set invisible the camera's preview in the UI. If the layer is not drawing, in newest versions the callback stop.
I only found a solution, but I cannot make it work. Someone know how to solve the problem of the callback preview WITHOUT show the image in the screen?
Exist another alternative, like open directly the camera in Native and use the callbacks in another thread?
This is very interesting, please try to reverse engineering this code HiddenCamera
try to grab the logic with this refs :
turn-your-android-phone-into-remote-spy
android-camera-capture-without
android-take-a-picture-without-displaying-a-preview

android: GLWallpaperService causing green screen

I am trying to create a live wallpaper using opengl (<2.0).
I imported and tried to run Robert Green's GLWallpaperService and Example here (using Eclipse SDK).
My phone is a Huwei Ascend Android 2.1. I already know it can run other opengl LWPs.
When I run the package, it just produces a solid green screen, and no shapes or anything.
Ive researched it alot and still cant figure out why this is happening.
I read a few times that the namespaces have to be changed to my package. But still no luck...
I tried linking his GLWallpaperService JAR library to my package as per instructed. Nope.
Any guidance would be much appreciated.
I fixed this on my Galaxy Nexus by adding
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
to onSurfaceCreated in MyRenderer.java.
try gl.glScale() in your Renderer Code. I also got the same problem and i figured out that my GLView was so much zoomed that i cant see anything. try to reduce scale.
My program wo
The example project you linked to had bugs in the rendering code, as others here have pointed out. It has since been deprecated and deleted for maintenance\workload reasons.
However, there's currently some example wallpaper code embedded into the main repository of GLWallpaperService. It's set up as a full Android application so developers can test using that example as needed.

Categories

Resources