Kivy native webview change url

42 views
Skip to first unread message

Ömer Yıldırım

unread,
Sep 10, 2018, 8:26:11 PM9/10/18
to Kivy users support
Hello Guys,
I use codes on this link(https://github.com/kivy/kivy/wiki/Android-native-embedded-browser) for native webview inside kivy. But when I want to change html file my codes can't load new html my app stay first html file. How can i change html file after i show any html. my change url function doesn't work. it is my codes:

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 run_on_ui_thread                                                   
from android import AndroidService
import time
WebView = autoclass('android.webkit.WebView')                                                   
WebViewClient = autoclass('android.webkit.WebViewClient')                                       
activity = autoclass('org.renpy.android.PythonActivity').mActivity                              
                                                                                                
class Wv(Widget):                                                                               
    def __init__(self, **kwargs):                                                               
        super(Wv, self).__init__(**kwargs)                                                     
        Clock.schedule_once(self.create_webview, 0)
        time.sleep(3)
        Clock.schedule_once(self.change_url, 0)                                                                                        
    @run_on_ui_thread                                                                           
    def create_webview(self, *args):                                                            
        self.webview = WebView(activity)                                                             
        self.webview.getSettings().setJavaScriptEnabled(True)                                        
        self.wvc = WebViewClient();                                                                  
        self.webview.setWebViewClient(self.wvc);                                                          
        activity.setContentView(self.webview)                                                        
        self.webview.loadUrl("file:///mnt/sdcard/aa.html")
    @run_on_ui_thread
    def change_url(self):
self.webview.loadUrl("file:///mnt/sdcard/a.html")
        
                                                                                                
class ServiceApp(App):                                                                          
    def build(self):
        service = AndroidService('my pong service', 'running')
        service.start('service started')
        self.service = service
        return Wv()                                                                             
                                                                                                
if __name__ == '__main__':                                                                      
    ServiceApp().run()

Reply all
Reply to author
Forward
0 new messages