top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Airplane mode control using Python?

+2 votes
1,790 views

I am trying to control Aeroplane mode on Android using Python code. I am running QPyPlus python. When I execute this code(that is widespread in the net),

#!/usr/bin/python 
import android droid = android.Android()
# go to airplane mode
 droid.toggleAirplaneMode()

droid.makeToast('exiting')

I get the error 'no such attribute Android()'.

One important thing is, I want to be able to do this without the need to reboot the Android device and any other working solution is also fine long as it is invokeable through Python.

posted Dec 22, 2013 by Chandra Javalkar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

Your code sample is identical to ones I've found online, so I assume it should work.

My best guess is that you have named your own file android.py, shadowing the library you're trying to import. Name it something else, delete all the *.pyc files in your directory, and try again.

answer Dec 23, 2013 by anonymous
Nope I havent named it as android.py and there are no .pyc files in my directory.
Here is the snapshot

$ python
Python 2.7.2 (default, Jul 20 2013, 22:54:57)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import android
>>> droid = android.Android()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Android'
>>>
Then perhaps your android module is not the one you think it is.
Try this to see what you get:

     >>> import android
     >>> print android
     .. this will show where it's imported from ..
     >>> dir(android)
     .. this will show the names available in the android module ..
     .. if any of them look like __version__ or VERSION, print that
     >>> android.__version__
I get a host of elements such as ['AndroidBrowser','AndroidService'...'KEY_CODE_1'..etc]
cant find any of __version__, VERSION, Android or anything
Similar Questions
+2 votes

I want to daemonify my python script on Android device. That is, it should be automatically invoked on boot up.

Appreciate your help.

+2 votes

How we can send mail with attachment in Python? Is it any prerequisite for it?

+2 votes

I want to use the stdout of child process as an input of another thread, but some how I am not able to read the stdout. Using Popen I have created a child process and stdout of it I have redirected to PIPE (because I don't want that to be printed on with my main process). Now using this statement,"Line=Proc.stdout.readline()" I want to read stdout of child process and I have to do operation on that. but somehow i am not able to read from stdout of child process.

Following is the code snapshot -

Proc = Popen(["python.exe","filename.py"],stdout=PIPE)

while True:
            Line = Proc.stdout.readline()
            print Line

Here,
Filename.py(Child process) is continuously printing "Hello World!!" in place of reading stdout of child process.

+2 votes

I'm trying to access Apples iCal-Server on a Mac OS X Snow Leopard Server via Python. The server is up and running and working with it via the iCal-Application is just fine. Now I need to access this server via Python to use it as backend for resource planning.

So how can I read the events within a time range from a user's calendar using python?

+2 votes

The problem description:

There are set of processes running on my system say process_set_1. Build a process agent which runs an asynchronous socket listening to incoming requests from process_set_1. Each process sends an id. The agent stores these ids in a dictionary and sends response that ur id has been accepted. Now agent process receives some data from another process (which is some sort of sister process for the agent). This data contains id along with a command which is to be sent by the agent to the process_set_1 through HTTP client over AF_UNIX socket, since each process in process_set_1 has a HTTP listening CLI. The process agent sends an HTTP request by recognizing id stored in dictionary to the process_set_1. A service running in the process_set_1 routes this HTTP command to the respective process.

Now my problem is the HTTP request which to be sent must go through AF_UNIX socket. I got this solution.

class UnixStreamHTTPConnection(httplib.HTTPConnection):

    def __init__(self, path, host='localhost/rg_cli',port=None, strict=None,
                 timeout=None):
        httplib.HTTPConnection.__init__(self, host, port=port, strict=strict,
                                        timeout=timeout)
        self.path=path

    def connect(self):
        self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        self.sock.connect(self.path)

But this cannot work since normal socket will not work and thus i thought of asyncore module in python. To use asyncore module again i will have to subclass asyncore.dispatcher. This class also contains connect() method.

Another problem is I don't know how asyncore module works and thus not able to find a way to mix the work of 1) listening forever, accept the connection, store id and the sock_fd.
2) accept data from the process' agent sister process, retrieve the sock_fd by matching the id in the dictionary and send it through the AF_UNIX socket.

Please help since i have already spent 2 days digging it out. Sorry if could explain my problem very well.

...