-
Notifications
You must be signed in to change notification settings - Fork 2k
Facing issues in making webbrowser.open(url) work #1287
Copy link
Copy link
Closed
Description
I am to make an android webview app with p4a using kivy example.
from kivy.app import App
from kivy.lang import Builder
from kivy.utils import platform
from kivy.uix.widget import Widget
import webbrowser
from kivy.clock import Clock
from jnius import autoclass
from android.runnable import run_on_ui_thread
WebView = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
activity = autoclass('org.kivy.android.PythonActivity').mActivity
urlc='https://www.google.co.in'
url='https://www.google.co.in'
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)
settings.setSupportZoom(True) # enables zoom
settings.setBuiltInZoomControls(True) # enables zoom controls
wvc = WebViewClient();
webview.setWebViewClient(wvc);
activity.setContentView(webview)
# webview.loadUrl('https://www.google.co.in')
if (url.find(urlc)==-1):
webbrowser.open(url)
else:
webview.loadUrl(url)
class ServiceApp(App):
def on_pause(self):
return True
def on_resume(self):
pass
def build(self):
return Wv()
if __name__ == '__main__':
ServiceApp().run()
I am trying for a behavior that all external link should open in webbrowser and internal link in webview.
But with above code app shows all links in webview only.
The command used to make apk:
p4a apk --private /home/user/kiviapps/webview/ --package=org.example.app1 --name "appname" --version 0.1 --bootstrap=sdl2 --requirements=kivy==master,pyjnius,android --permission INTERNET
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels