7.7 Testing Out the Android Client
Time to test out the application on a real X10 light switch. Assuming the Rails-based X10 web application is working as expected, start up your Rails development server on the same network/subnet as the emulator in Figure 28, Running the Light Switch application.

Figure 28. Running the Light Switch application
Use the same port number as the one we assigned in
the my_server_ip_address_and_port_number
string from our Android application. For example, in the case of
192.168.1.100:3344
, the IP
address is 192.168.1.100 and the port number is 3344. Pass this as
a command-line parameter when launching the Rails server instance,
like this:
>
rails s -p3344 |
With the rails development server now running on port 3344 and waiting for inbound requests on the same local area network as your Android emulator or device, click the On/Off toggle button.
Um, nothing happened. Why?
There is one more important setting we have to make
in the Light Switch application configuration. We have to respect
the Android application security model and tell the Android OS that
we want to allow our application to Use the Internet
so that we can have our
outbound HTTP requests reach the outside world. To do so,
double-click the AndroidManifest.xml
file and add the following
line just above the closing manifest tag, like this:
<uses-permission android:name="android.permission.INTERNET" > |
|
</uses-permission> |
The entire AndroidManifest.xml
file should now look like
this:
<?xml
version="1.0" encoding="utf-8"?> |
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
|
package="com.mysampleapp.lightswitch" |
|
android:versionCode="1" |
|
android:versionName="1.0" > |
|
<application
android:icon="@drawable/icon" |
|
android:label="@string/app_name"
> |
|
<activity
android:name=".LightSwitch" |
|
android:label="@string/app_name"
> |
|
<intent-filter> |
|
<action android:name="android.intent.action.MAIN" /> |
|
<category
android:name="android.intent.category.LAUNCHER"
/> |
|
</intent-filter> |
|
</activity> |
|
</application> |
|
<uses-permission
android:name="android.permission.INTERNET"
> |
|
</uses-permission> |
|
</manifest> |
Recompile and run the Light Switch application with the new permission setting and click the toggle button. If everything worked as planned, you should see the Rails server report something similar to the following successfully received request:
Started
GET "/command/on" for 192.168.1.101 at Sat Mar 21 19:48:10 -0500
2011 |
|
Processing by CommandController#cmd as HTML |
|
Parameters: {"cmd"=>"on"} |
|
Rendered
command/cmd.html.erb within layouts/application
(11.7ms) |
|
Completed 200 OK in 53ms (Views: 34.7ms |
ActiveRecord: 0.0ms) |
You should also see the light turn on! Click the toggle button again. It should generate a similar report for the off command:
Started
GET "/command/off" for 192.168.1.101 at Sat Mar 26 19:52:30 -0500
2011 |
|
Processing by CommandController#cmd as HTML |
|
Parameters: {"cmd"=>"off"} |
|
Rendered
command/cmd.html.erb within layouts/application
(13.2ms) |
|
Completed 200 OK in 1623ms (Views: 40.0ms
| ActiveRecord: 0.0ms) |
Consequently, the light should now switch off.
On rare occasions, one other issue you may encounter when you attempt to install the Light Switch application on your Android phone is an expired debug key. Android’s security model requires a signed key to execute code on an Android device. The signed key should have been automatically generated and configured when you installed the Android SDK, but in the event that an expiration message occurs, follow the signing procedure in the Android SDK documentation to generate a new key.[75]
For more details on installing Android programs onto an Android device from the Eclipse environment, review the Android SDK documentation on running Android applications on an emulator and on a device.[76]