Skip to content

Instantly share code, notes, and snippets.

@bstaint
Created September 3, 2019 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bstaint/bd40f2189105e50613975fcc9eb99d99 to your computer and use it in GitHub Desktop.
Save bstaint/bd40f2189105e50613975fcc9eb99d99 to your computer and use it in GitHub Desktop.
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