sl4a
sl4a copied to clipboard
python webbrowser support
From @GoogleCodeExporter on May 31, 2015 11:25
What steps will reproduce the problem?
1. import webbrowser
2. webbrowser.get().name
3. error : can't find...
What is the expected output? What do you see instead?
a default browser name
What version of the product are you using? On what operating system?
r17 Python 2.6.2
Please provide any additional information below.
webbrowser seems buggy, is there an otehr prefered way to control the
browser ?
Original issue reported on code.google.com by [email protected]
on 7 Mar 2010 at 8:34
Copied from original issue: damonkohler/android-scripting#216
From @GoogleCodeExporter on May 31, 2015 11:25
Original comment by [email protected]
on 6 Nov 2010 at 9:44
- Added labels: Type-Enhancement
From @GoogleCodeExporter on May 31, 2015 11:25
It is possible to add a default browser to the list of pythons
webbrowser-module. The module provide for this the method ''register''.
Question:
The only question is which browser is available on the android plattform and
how you can call it from python-code?
Answer:
You can make it possible if you use the function ''droid.view(url)'' of the
SL4A API, that can call an URL in a webbrowser.
The same would happen if you programm an app in java for android and call with
an ''Intent'' the ''Intent.ACTION_VIEW'', give the intent an url and start the
created Intent with the method ''startActivity(intent)''.
So back to the modification of the webbrowser-modul of python.
Now you can create a Webbrowser class in python like this:
# Web browser support for Android combined with the SL4A project.
class AndroidSL4AWebbrowser(object):
def __init__(self):
import android
self.droid = android.Android()
def droid_open(self, url):
self.droid.view(url)
def open(self, url, new=0, autoraise=True):
self.droid_open(url)
def open_new(self, url):
self.droid_open(url)
def open_new_tab(self, url):
self.droid_open(url)
and add this class to the list of pythons webbrowser-modul with the
''register''-method like this:
register('androidsl4awebbrowser', AndroidSL4AWebbrowser, None, -1)
After this you can call in the python-code:
url = ''www.google.de''
webbrowser.open(url)
The only problem is, that the call of the webbrowser.open(url) is not asynchron.
But this is solvable with a Thread.
Original comment by [email protected]
on 4 Oct 2012 at 4:12
Attachments: