Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView from NDK in android

Is there a way to open a WebView from android ndk? We are able to call a java method from jni c++ file and we are able to open a webview but we need to open a webview directly from android ndk without java interference.

like image 262
tk120404 Avatar asked Nov 14 '22 10:11

tk120404


1 Answers

You can't access Java UI from NDK code. The NDK's got basic functionality to draw stuff on the screen, suitable for writing games, but that's it.

If you want to use WebView you're going to have to embed it inside a Java UI and then call out to it via JNI. I can't really comment further without more details about what it is you're trying to do, but the usual use cases are:

  • game wants to launch a URL: game calls out to Java via JNI and the Java side launches it as an intent.

  • game wants to view some HTML in a custom UI: game calls out to Java via JNI and the Java side launches an Activity with a WebView in it.

There are also plenty of ways to cheat, e.g. having a custom activity with no titlebar and a transparent background with a WebView on it appear on top of your NativeActivity. It all depends what you want to do, but it's all going to involve JNI.

like image 113
David Given Avatar answered Nov 16 '22 02:11

David Given