msoftware / android-scripting

Automatically exported from code.google.com/p/android-scripting
0 stars 0 forks source link

python webbrowser support #216

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 years ago
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: