tags:

views:

144

answers:

5

I would like to write an Android application that can be activated by sending it a command from a web site. Is this possible? Actually, the app would be running on the phone and I would be sending it a command via HTTP.

A: 

This is completely possible. Just start a webserver on your phone. For instance: http://l00g33k.wikispaces.com/micro+HTTP+application+server

Damon
This will not work over many 3G networks (no public IP address) and has all the security ramifications of running a Web server on an actual server without most of the tools (e.g., firewalls) to manage them.
CommonsWare
+1  A: 

You could have the server send an SMS message to Android. On the Android side, your app listen can listen for the SMS message and execute the appropriate command. Here is a question about sending SMS from a server. Here is some help on using sms in android.

I'm not sure if you can keep your SMS messages private to your app. Ideally you wouldn't want the user to see these SMS messages as a text message. Perhaps you could just delete the message as soon as it is processed.

Jay Askren
+2  A: 

You could have your application maintain a connection to the webserver waiting for a command. This kind of technique is often used in AJAXy websites that update in real time, and is called the "comet" pattern or "long polling".

Basically, your client (the app on the phone in this case) requests a certain page. Your webserver (or PHP or whatever you're using) checks to see if there are any outstanding messages or commands to be sent to the client, if not it keeps the connection open and waits either until a message for the client is received, or until a certain timeout.

There are a couple of obvious drawbacks to doing this:

  • Your webserver needs to maintain 1 open connection per user of the application. Depending on the server, this can tie up resources fairly quickly if you have lots of users
  • Your application will be using resources constantly as it will also have to maintain an open connection and re-establish it periodically

This is all assuming you need near-realtime responses to your commands. If they can be delayed, normal polling should suffice.

Chris Smith
A: 

A bit of tooting my own horn:) Now with that addressed...

This will not work over many 3G networks (no public IP address)

If no general public access is required, you can use two SSH connections to an SSH server. I have done it many times and is as secure as your SSH setup.

and has all the security ramifications of running a Web server on an actual server without most of the tools (e.g., firewalls) to manage them

If general public access is desired, you can do it with one SSH connection from the phone to the SSH server. You need to open a port on the SSH server but you don't need firewalls management because you can run another Perl script to filter the source address and forward to the phone through the SSH connection. There is another thing that is good/bad about it depending on your view. Since it requires an active SSH/Android ConnectBot connection, you know when it is active and it drops off when you close the SSH connection. To me this is added security. And I have done this to send KML files to Google Maps' Google server (KML file must be publicly accessible without password to the Google server even though the file is on your phone; I filter by Google's IP address.)

l00g33k
+4  A: 

As of Android 2.2, you can start playing with the cloud to phone messaging system (more information here)

Yann Ramin