python-for-android icon indicating copy to clipboard operation
python-for-android copied to clipboard

add android:usesCleartextTraffic="true" to sdl2

Open sharkguto opened this issue 5 years ago • 2 comments

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()

sharkguto avatar Oct 12 '20 03:10 sharkguto

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

vesellov avatar Oct 22 '20 19:10 vesellov

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\""

vesellov avatar Feb 17 '21 11:02 vesellov