python-for-android
python-for-android copied to clipboard
add android:usesCleartextTraffic="true" to sdl2
add android:usesCleartextTraffic="true" to sdl2 for using webview with kivy
from kivy.app import App
from jnius import autoclass
from kivy.clock import Clock
from android.runnable import run_on_ui_thread
from kivy.uix.widget import Widget
WebView = autoclass("android.webkit.WebView")
WebSettings = autoclass("android.webkit.WebSettings")
WebViewClient = autoclass("android.webkit.WebViewClient")
activity = autoclass("org.kivy.android.PythonActivity").mActivity
@run_on_ui_thread
def create_webview(*args):
webview = WebView(activity)
webview.getSettings().setJavaScriptEnabled(True)
webview.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW)
wvc = WebViewClient()
webview.setWebViewClient(wvc)
activity.setContentView(webview)
webview.loadUrl("http://18.15.178.11:9999")
class Wv(Widget):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.__functionstable__ = {}
Clock.schedule_once(create_webview, 0)
class ServiceApp(App):
def build(self):
return Wv()
if __name__ == "__main__":
ServiceApp().run()
I would like to mention here my PR also, because it is very related... I am adding a parameter for usesCleartextTraffic that can be set via buildozer.spec file... not everyone needs it to be set to true, right ? ;)))
https://github.com/kivy/python-for-android/pull/2338
My pull request #2338 was merged and now I think people can achieve same result without modifying the XML template. You can pass input parameter like that and hopefully it should work:
--extra-manifest-application-arguments="android:usesCleartextTraffic=\"true\""