Skip to content

Instantly share code, notes, and snippets.

@bstaint

bstaint/webview.py Secret

Created Sep 3, 2019
Embed
What would you like to do?
Android native embedded browser modify
import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.utils import platform
from kivy.uix.widget import Widget
from kivy.clock import Clock
from jnius import autoclass
from android.runnable import Runnable
WebView = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
activity = autoclass('org.renpy.android.PythonActivity').mActivity
def run_ui_thread(f, *args, **kwargs):
# args/kwargs to runnable was a bug, fixed in master
Runnable(f)(args, kwargs)
class Wv(Widget):
def __init__(self, **kwargs):
super(Wv, self).__init__(**kwargs)
Clock.schedule_once(self.create_webview, 0)
def create_webview(self, *args):
def _create_webview(*args):
webview = WebView(activity)
webview.getSettings().setJavaScriptEnabled(True)
wvc = WebViewClient();
webview.setWebViewClient(wvc);
activity.setContentView(webview)
webview.loadUrl('http://www.ip138.com')
run_ui_thread(_create_webview, *args)
class ServiceApp(App):
def build(self):
return Wv()
if __name__ == '__main__':
ServiceApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.