Skip to content

Facing issues in making webbrowser.open(url) work #1287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
apdd2003 opened this issue May 25, 2018 · 2 comments
Closed

Facing issues in making webbrowser.open(url) work #1287

apdd2003 opened this issue May 25, 2018 · 2 comments

Comments

@apdd2003
Copy link

apdd2003 commented May 25, 2018

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

@inclement
Copy link
Member

So the point is that either webbrowser.open doesn't open in a new Activity, or url.find(urlc) never equals -1? I would test each of these things individually to try to understand the problem, I don't know offhand why this wouldn't work.

@inclement
Copy link
Member

Closing as stale, feel free to open a new issue with specific issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants