Monday, February 12, 2007

Free Java games for your SonyEricsson phone

This post is to walk everyday owners of Sony Ericsson phones, such as the w300i or w800 series through the process of obtaining free (legal) games that can be downloaded directly to your phone and installed, without a data plan and without data charges, as long as you have the regular USB cable (and a computer with Internet and USB). This cable comes with the phone if you order it online from Cingular. If you don't have one, you can get it here. Yours might not look exactly like this one, but if it came with your phone it should work. You will also need a memory card to do the install. This phone is kind of worthless as a Walkman without the memory card, so you might want to go ahead and get the full 1 gig Memory Stick Micro (m2) card here. These are the only items you will have to purchase for this process, and they are useful for other things, such as playing music and synchronizing your phone calendar with Outlook too, so you will continue to use them.

If you don't have the cable, I believe (though I haven't tested it) you can use bluetooth instead. This involves having bluetooth hardware on your computer, and turning it on on the phone as well, and making the connection, all of which is beyond the scope of this article. If you have success with this, please post below in the comments. The remainder of this article assumes cable use only.

Once you have the cable, and you have installed the memory card (just slide the back off the battery compartment, and there is a small hole labelled M2; with the phone face down, the card should be face up and the arrow should point toward the phone), you need some free software from SonyEricsson. Their site is a little difficult to navigate, so I will walk you through it as of today. If you're in the US, go to this link and choose your phone from the list on the bottom. To get to this link from the main site, simply go to http://www.sonyericsson.com and choose your country, and then choose product support from the start page under "I have a Sony Ericsson phone." Once you have chosen your phone from the drop-down list, the list will appear blank again, and move to the left, which is weird. However, above that blank list should be a picture of your phone, indicating that you have properly chosen the phone already. Under Software and Setup, you'll see a link for Software downloads. This is the one you want. When you click that link, you should see a link to Sony Ericsson PC Suite. The direct link is here for my phone, but I recommend going through the steps to make sure you get the one that is compatible with your phone. Don't worry if the picture suddenly changes from, say, a W300i to a W800i, like I said the site is goofy. While you are there, you may want to get disc2phone, which will allow you to put music on your phone; a subject for another day.

Once on that page, you'll see a tiny link at the bottom saying "download setup xxx". Do this, and install the program. It will appear in your task menu as a picture of a candybar cell phone, and it will be installed as Sony Ericsson/Sony Ericsson PC Suite from the start menu. Now you are ready to plug in the USB cable and then plug the cable into your phone. As soon as you plug the phone in, it will want you to select "file transfer" or "phone mode" from the phone itself. Choose "phone mode"; you almost never need file transfer except when you are running disc2phone. Windows may go through some of its gyrations to install USB drivers and such; reboot when it asks and so on. At some point the PC Suite software will be connected to your phone, and the icon will lose it's red "X" and will just look like a phone.

At this point, you are ready to get some free games and send them to the phone. You can find some at midlet.org (be sure to click through to midlet.org, not midlet.com). You can get games, utilities, and so on. They're free, so they might not all work with your particular phone. If you get stuck in a game that you can't seem to leave, just hold down the back button for a menu. Let's say you choose games, board, and you want Dots 1.0.0. There will be two downloads, a jar and a jad. Generally you only need the jar file. Save it to your desktop (you might need to right-click and choose Save target as...). Then right-click on the cellphone icon in your task tray, and choose File Manager. This will bring up an explorer-like interface with your phone listed in it. Double-click on the phone, and you will see Memory Stick and Phone Memory. Use the + sign tree on the left side to explore the folders below this. Under Memory Stick is MSSEMC, under that is Media files, and under that is other. Click on other in the tree, and the area to the right should appear blank (unless you've done this before). Now open up a regular windows explorer (Start/My Computer and hit Up icon to get to the desktop). From there, drag your .jar file (such as Dots.jar) from the desktop into the SE explorer "other" folder. The phone may prompt you at this point to accept the file. Say yes.

Now that the .jar file is on the phone, you are ready to install it. Go to the file manager on your phone (you can leave it connected for the time being). The file manager is under the regular phone menu, and it has an icon that looks like a folder. Select the file menu, and scroll down to the "other" folder and open it. In there should be your jar file. Choose install, and it will ask if you want it in games or applications. Games is most likely. When it is done, you can start it right away, or you can get to it later from the entertainment icon (looks like a ps3 controller), under games. If you have trouble getting out of a game, hold down the back button for a menu.

In addition to midlet.org, you can also go to Sony Ericsson itself for a number of free games (this link will get you to the wap server to choose your phone; your phone will have a set of applications and downloads). If you try to navigate to this link you can't get there, so just click on that link and select your phone-name. Anywhere else you can find J2me .jar files (known as midlets) might also work for your phone. Good luck! I will try to answer any questions posted below.

Cell Phone development - w300i



History

In November, the two-year contract on my cell phone ran out. This allowed me to upgrade my phone to a new phone. I really only needed to get a new battery, because the one I had was down to about a four-hour recharge cycle. However, it was cheaper to get a new and better phone than to get a new battery, because of the contract extension. I initially looked at the Motorola RAZR, and while researching it, found some hacking information. As a professional developer, this got me thinking about programming the phone in more official ways than hacking, and this led me to the Java 2 Micro Edition (J2ME). I also wanted a phone that had good mp3 playback, so I wouldn't have to carry a separate iPod. What I really wanted was the iPhone, of course, but it hadn't been announced yet. In the end, I selected the Sony Ericsson w300i, a nice Walkman phone packed with features for the price (it was $9.99 with the Cingular contract extension, since reduced to $0.00). As a consolation, a few days after the iPhone announcement, Sony Ericsson announced eight new phones, which have similar development environments to the w300i.

w300i features
The w300i has J2ME support, including the JSR184 3D gaming API as well as a Mascot Capsule micro 3D. It also supports bluetooth for headset use, computer USB connection, FM radio, mobile TV and e-mail, and multiplayer gaming. As you will see, this last bit was something of a sticking point with me, but as of today it has a happy ending! More on that later; first I want to walk you through getting started with development for this device.

Developer signup
Having received the phone just in time for Christmas, I immediately began looking around for software development kits (SDK's). The best place to start, if you are a Cingular customer, is here, at developer.cingular.com. You will have to create an account, but it is free. Within that site is a lot of good information about phones, including Sony Ericsson. If you want to jump right in and get started with an SDK for the SE phones, it is here. The sites seem to follow the pattern of developer.x.com, including Motorola and others. Before you install the SE SDK, though, you will have to click on the release notes link to get your prerequisites set up. This includes the Sun J2SE SDK if you don't already have it. You will also need DirectX 8.1 or later, to run the emulators. With these installed, you are ready for the SE SDK mentioned above.

Sample projects
Once you have installed the SDK, you will have a new set of menu items under Sony Ericsson/Java ME SDK for CLDC. CLDC and MIDP are abstractions/subsets of Java that work for mobile phones. The w300i and most modern mobile phones use CLDC 1.0 and MIDP 2.0, which means your phone emulator will appear under the WTK2 menu under Sony Ericsson/Java ME SDK for CLDC/WTK2. You can also integrate all of this into an IDE, but you don't need to; it runs fairly smoothly as it is. The first program to run is Default Device Selection, which you only need to run once. Choose SonyEricsson_w300_Emu from the dropdown and hit ok. Done. Now you will want to run ktoolbar under the same menu (WTK2). There should be a number of sample projects prepopulated into this program, so you can just pick Open Project and choose one to run.

Bluegammon
There is one sample that is a fairly complete application, called Bluegammon. It plays backgammon as single or multi player, through bluetooth. Or at least it would, if Cingular's security on this phone weren't so draconian. At any rate, without even connecting the phone you can run this program in the emulator, simply by opening the project, selecting the phone you want to emulate, and choosing run. A phone interface will come up, and the important thing to note is that the only way to interact with the application is through the buttons of the phone. You will try clicking on the phone screen itself, just out of habit, but when it doesn't work, you will remember that the buttons of the phone are what you need to click on. When you are ready to build the .jar and .jad files, which are the actual distributable executables, you just go to the ktoolbar Project menu and choose Package/Create Package. Don't worry about obfusacting or signing for now. If you have a Cingular-branded phone, the signing won't do much anyway unless you are already a Cingular Preferred vendor. I'll cover debranding your phone in a later post.

Installing programs
This post will walk you through installing .jar files onto the phone, through the data cable, without even using the SDK. Anyone can do this, without signing up as a developer. Here, I will cover on-device debug, and installing the projects that you have built from sample code or on your own.

Connecting to phone
From ktoolbar, you can open and build a project, run it, and create the .jar files, as I have discussed. Once you have done that, what you really want to do is run the program on the phone. The documentation is not very clear on this, but I will clue you in to the simple steps you need to do. From the "All Programs/Sony Ericsson/Java ME SDK for CLDC" menu on your computer, there is a program called "Connection Proxy Settings". This opens a file in notepad. The only thing you need to do in that file is change the comm: setting to comm: COM4. This should work for most computers, but you may have to go higher. Save that file and exit notepad. With your phone plugged in, and in Phone mode (not File Transfer), then choose the DeviceExplorer from the same CLDC computer menu. (It's OK if you have PC Suite installed and it connects to that too). The DeviceExplorer will automatically start the Connection Proxy. If the Connection Proxy fails to connect to your device, you might have to choose the settings icon (looks like a little green gear) from its menu. This will let you choose a port and baud rate. Again you want COM4.

Connection troubleshooting
In order to get connected, I had to open the PC Suite program (the little cell-phone icon in your system tray) and from its menu choose Tools/Phone Monitor Options... which brings up a dialog box. In that dialog box, there is a tab called COM ports. Here you want to make sure that any real com ports you have on your computer are disabled. That's a little anti-intuitive, but the device proxy drivers set up a fake com port above the ones on your computer. Reserved can be left at No. IMPORTANT NOTE: never shut down your computer with the phone connected. This messes up PC Suite and causes a program called generic.exe to crash when you reboot. It also makes your computer really slow. If this happens, just connect and unconnect the phone again, and restart the computer (this may take a while).

On-device debugging
Contrary to what I thought at first, you don't have to install anything special onto your phone to do on-device debugging. Once DeviceExplorer is connected and running, you should see a menu of stuff on your phone on the left, and a WTK applications folder on the right. If you open up this folder, you will see all of your projects from ktoolbar under it. If you open one of these, such as Bluegammon/bin, you will see your .jad and .jar files. To install to the phone, just right-click the .jad or .jar and choose Install. Note that this lets you skip all the stuff outlined in my other post. This puts the program on your phone, on the left. Then you can select the item on the left, and click the "play" icon in the menu above it. This starts the program on your phone. Now you can see the output from that program running in the window below. This includes System.out.println output, as well as exceptions. If you have Cingular, just go to the menu on the phone and try to play via bluetooth and set up a server. This will cause a security exception unless you sign the program with a Cingular Preferred certificate, and turn on bluetooth manually on the phone. Alternately, you can debrand the phone to overcome this limitation, through something like wotanserver.com or davinciteam.com. This is different from and independent from unlocking. I will walk through this process in a future post.

Final important note:
Once you have DeviceExplorer running, the order of shutdown is important, or it will cause their programs to hang. Start by shutting down the device explorer. This will leave the device proxy running and connected. Disconnect before shutting this down, or it will hang. You can disconnect the phone without exiting the PC Suite program; that is, leave it minimized in the system tray. It will show up with a red X again when you exit it. You can shut down ktoolbar whenever you want; I haven't had issues with it.