question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

webbrowser.open() doesn't work on Android with bootstrap=sdl2

See original GitHub issue

webbrowser.open() doesn’t work on Android with bootstrap=sdl2, but work with pygame. No error, no crash, just nothing happens. Is there any solution to fix this issue?

Android Version: 6.0.1

import webbrowser
webbrowser.open('http:/www.kivy.org/')

From buildozer logs

# Run 'python -m pythonforandroid.toolchain
 --color=always
 --storage-dir=/home/hdias/Work/mobile_app/.buildozer/android/platform/build create
 --dist_name=mobile_app 
 --bootstrap=sdl2
 --requirements=pycrypto,plyer==master,kivy==master --arch armeabi-v7a --copy-libs'

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mrhdiascommented, Oct 11, 2016

Thanks for the clues, but your solution does not work because it is not complete. Can you fix the code with this? http://python-for-android.readthedocs.io/en/latest/apis/

from kivy.utils import platform

def launch_webbrowser(url):
    import webbrowser
    if platform == 'android':
        from jnius import autoclass, cast
        def open_url(url):
            PythonActivity = autoclass('org.kivy.android.PythonActivity')
            activity = PythonActivity.mActivity
            Intent = autoclass('android.content.Intent')
            Uri = autoclass('android.net.Uri')
            browserIntent = Intent()
            browserIntent.setAction(Intent.ACTION_VIEW)
            browserIntent.setData(Uri.parse(url))
            currentActivity = cast('android.app.Activity', activity)
            currentActivity.startActivity(browserIntent)

        # Web browser support.
        class AndroidBrowser(object):
            def open(self, url, new=0, autoraise=True):
                open_url(url)
            def open_new(self, url):
                open_url(url)
            def open_new_tab(self, url):
                open_url(url)

        webbrowser.register('android', AndroidBrowser, None, -1)

    webbrowser.open(url)

launch_webbrowser('http://www.kivy.org')
1reaction
inclementcommented, Jul 27, 2016

For reference, the specific code you need is as below (you can use this instead of the android module if you like):

from pyjnius import autoclass

def open_url(url):
    Intent = autoclass('android.content.Intent')
    Uri = autoclass('android.net.Uri')
    browserIntent = Intent()
    browserIntent.setAction(Intent.ACTION_VIEW)
    browserIntent.setData(Uri.parse(url))
    currentActivity = cast('android.app.Activity', mActivity)
    currentActivity.startActivity(browserIntent)

# Web browser support.
class AndroidBrowser(object):
    def open(self, url, new=0, autoraise=True):
        open_url(url)
    def open_new(self, url):
        open_url(url)
    def open_new_tab(self, url):
        open_url(url)

import webbrowser
webbrowser.register('android', AndroidBrowser, None, -1)

I’d like to add this to the doc somehow, but am not sure where to put it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - webbrowser.open() doesn't work on Android
I'm using QPython and Kivy Launcher to run my Python code on Android. QPython Log of webbrowser. get() or webbrowser.
Read more >
Kivy app working on PC but not on Android with Buildozer ...
Test this by creating a HelloWorld app, add two things: import webrowser and in on_start() put webbrowser.open(). Does this crash in the same...
Read more >
python-for-android Documentation
One useful facility of this module is to make webbrowser.open() work on Android. You can replicate this effect.
Read more >
Platform::Sdl2Application class | Magnum C++ docs
The bootstrap application assumes that SDL2 and ANGLE is built as DLL and both Corrade and Magnum are built statically. Assuming the native...
Read more >
Build an Android application with Kivy Python framework
Getting started with Kivy. First, you'll need a new directory for your app. Make sure you have Python installed on your machine and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found