简体   繁体   中英

webbrowser.open() doesn't work on Android

webbrowser.open() works on Windows 7; Python 2.7 opens my default web browser (Chrome) on my Windows machine no problem.
My simple code to analyze CSV data works perfectly on both Windows and Android (4.1). webbrowser.open() or.get() does not work on Android with Firefox and Chrome.
I'm plotting/drawing analyzed data on Google Map on a browser. It's such a simple thing to do yet Python doesn't even find a "runnable" browser on Android.

I'm using QPython and Kivy Launcher to run my Python code on Android.

     QPython Log of webbrowser.get() or webbrowser.open(); 
     "webbrowser.Error: could not locate runnable browser."

Even if webbrowser.get(browser_path).open(url) worked, it's a bit of pain having to find a "runnable" browser among many possible browsers' path.

What API/module/trick do you wizards use, Pyjnius to call Android API?

"Mmmm, pieThong, uuugghhh..."

Using webbrowser is not an option on Android so far. Instead you can use Pyjnius :

from jnius import autoclass, cast

def open_url(url):
    Intent = autoclass("android.content.Intent")
    Uri = autoclass("android.net.Uri")
    PythonActivity = autoclass("org.kivy.android.PythonActivity")

    i = Intent(Intent.ACTION_VIEW)
    i.setData(Uri.parse(url))

    current_activity = cast('android.app.Activity', PythonActivity.mActivity)
    current_activity.startActivity(i)

Reference: Pyjnius documentation

Try this:

import webbrowser

url = 'http://docs.python.org/'

webbrowser.open(url)

Since Chrome is already installed on Android, one only needs to identify the URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM