damonkohler / sl4a

SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device.
Apache License 2.0
2.42k stars 804 forks source link

python webbrowser support #269

Open damonkohler opened 9 years ago

damonkohler commented 9 years ago

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 alexandr...@gmail.com on 7 Mar 2010 at 8:34

Copied from original issue: damonkohler/android-scripting#216

damonkohler commented 9 years ago

From @GoogleCodeExporter on May 31, 2015 11:25

Original comment by damonkoh...@gmail.com on 6 Nov 2010 at 9:44

damonkohler commented 9 years ago

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 valerij....@gmail.com on 4 Oct 2012 at 4:12

Attachments: