python - Saving current URL on Android Kivy Application -



python - Saving current URL on Android Kivy Application -

my code:

import kivy kivy.app import app kivy.lang import builder kivy.utils import platform kivy.uix.widget import widget kivy.clock import clock jnius import autoclass android.runnable import run_on_ui_thread webview = autoclass('android.webkit.webview') webviewclient = autoclass('android.webkit.webviewclient') activity = autoclass('org.renpy.android.pythonactivity').mactivity 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) @run_on_ui_thread def create_webview(self, *args): webview = webview(activity) webview.getsettings().setjavascriptenabled(true) wvc = webviewclient(); webview.setwebviewclient(wvc); activity.setcontentview(webview) webview.loadurl('www.google.com') class serviceapp(app): def build(self): homecoming wv() def on_pause(self): homecoming true def on_resume(self): homecoming wv() if __name__ == '__main__': serviceapp().run()

the application working great want save current url when on_pause event fire , when on_resume event want homecoming url.

i didnt figure out how this.

suggestions?

edit: curious, , went on check things. indeed java.lang.runtimeexception: probable deadlock detected due webview api beingness called on wrong thread while ui thread blocked. it's necessary subclass webviewclient , not sure how in jnius.

i think can access url no problem. widget tree looks this: serviceapp -> wv did not create webview fellow member of wv. should do:

@run_on_ui_thread def create_webview(self, *args): self.webview = webview(activity) self.webview.getsettings().setjavascriptenabled(true) wvc = webviewclient(); self.webview.setwebviewclient(wvc); activity.setcontentview(self.webview) self.webview.loadurl('www.google.com')

after this, think do:

class serviceapp(app): def build(self): self.wv = wv() homecoming wv def on_pause(self): # url, don't know android api # http://developer.android.com/reference/android/webkit/webview.html self.wv.webview.geturl() homecoming true def on_resume(self): # here have doubts why create widget ok self.wv = wv() homecoming wv

there many parts not sure, , things needs testing ensure it's safe proceed this, it's start. 2 cents.

android python python-2.7 webview kivy

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -