-
-
Save bstaint/bd40f2189105e50613975fcc9eb99d99 to your computer and use it in GitHub Desktop.
Android native embedded browser modify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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