A flag icon shows that page is written in: English, Japanese

Android made up to date

Android is a much better application development framework for mobile devices than iPhone's. JavaFX will be the competitor of Android in the future.

Buying Android in Japan

Subscribe yourself and you can purchase the devphone G1 from Android Market . It will cost $399 but come with a sliding keyboard and among others, the best operating system in the mobile market!

If you have any problem with the phone, you should actually contact Brightstar, they are the ones selling those devices. See under "returns" at http://android.brightstarcorp.com/help.htm .

When you are out of home and have an InfoNotice sheet, you should probably bring it to either of places like these to get the devphone:

Preparing a SIM Card

In the meantime, you also have to prepare a SIM card that allows you to access through WCDMA, unless you never stay in Japan. The SIM card will be provided when you purchase a Japanese mobile phone. (I personally bought Vodafone 804SH which now belongs to Softbank and have been using the card for a long time.)

Remove the card from the old phone, and then insert it to the new one with Android OS. T1 mobile's G1 has the card slot under the back cover next to the battery.

Reaching Softbank's APN (Access Point Name)

If you go with Softbank, use iPhone3G access point `smile.world' to apply their fixed-charge packet full service . That means, in G1, press menu button at the first place, select APN settings and add a new item to edit the properties this way:

Then, follow the screen instructions and proceed with Google account registration.

Use as a phone

Once you've signed in and your phone is registered on the network, the Home screen will appear.

To make a call, choose `dialer' from the Home view displayed, or simply press the Call button at the bottom left of your phone.

Make sure you can dial numbers with the soft pads shown in the screen.

Open an application

Tap the tab at the bottom of the Home screen to reveal all the application icons, then simply tap the icon. You can also roll the trackball to highlight the icon, then click the trackball to open it.

You can slide your finger left or right along the screen to reveal the full width of the Home screen. Press & hold the screen to open a menu of shortcuts and widgets that you can add to the screen.

Enabling USB device driver in Debian/Ubuntu

To make a connection from your PC to the phone, you will need to have a device driver installed into the operating system such as Linux, Windows or MacOS X.

  1. Login as root and create this file: /etc/udev/rules.d/51-android.rules.

    For Gusty/Hardy, edit the file to read:

    SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"

    For Dapper, edit the file to read:

    SUBSYSTEM=="usb_device", SYSFS{idVendor}=="0bb4", MODE="0666"

  2. Now execute:

    $ sudo chmod a+rx /etc/udev/rules.d/51-android.rules

Connect the phone using the USB cable that came with it, and you should be able to mount the microSD card of 1GB or so that should be inside the phone.

Update the firmware to the version 1.6 (formerly 1.5)

The htc Development Center officialy provides the updated firmwares for Android Dev Phone. Note the firmware versions are for devphones only. The programs will not work on the T-Mobile G1 or any other phones running Android.

However if something goes wrong, personal builds are also available from third parties. One of such sites is sapphire-port-dream .

Download the Radio Image and Recovery Image with whatever Android version you want, while the latest one is recommended to install.

Version Type of Image File
Android 1.6 Radio Image ota-radio-2_22_19_26I.zip
Recovery Image signed-dream_devphone_userdebug-ota-14721.zip
  1. Ensure that a SD card is inserted in the device and boot the device normally.

  2. Connect the device to your development machine over USB.

  3. At a command line, ensure that adb recognizes your device by issuing this command with root :

    $ sudo ..../android-sdk-linux_86/tools/adb devices

    You should see your device in the console output now.

    List of devices attached HT92RLZ00213 device

    If it fails with no permissions, ensure you have enabled the USB driver in your Debian as explained before. You also need to check you have started the adb daemon as root :

    $ ps aux | grep adb

  4. Run adb with a push command to copy the contents of the radio image package to the update.zip file in the device's mounted SD card.

    $ adb push ota-radio-2_22_19_26I.zip /sdcard/update.zip

    The command prints the number of bytes copied and the elapsed time, then completes.

    956 KB/s (9181622 bytes in 9.379s)

    However, note that the files are still being copied in the background, so wait a minute or two before continuing. If you continue too soon and terminate the operation before it is complete, you will get a bad update.zip error later, when you try to install the update. Use this command to ensure that the transfer completed.

    $ adb shell sync

  5. Reboot the device into recovery mode by holding down the HOME key during reboot. When the device enters recovery mode, it displays a "!" icon.

  6. With the recovery console displayed, open the sliding keyboard and hold down the ALT+l key combination to enable log output in the recovery console.

  7. Next, hold down the ALT+s key combination to install the update. An installing update icon and progress bar (or a similar status message) are displayed. When the progress bar completes, the installation is finished.

  8. Press the HOME-BACK key combination to write the radio image, update the firmware, and automatically reboot. Note that if you do not use HOME-BACK at this point, the device will not load the updated radio image. After writing the radio image, the device shows a updating firmware icon for a few seconds and then automatically reboots in normal mode.

To copy the recovery image to the device SD card, follow these steps:

  1. Ensure that you have inserted the SD card containing the updated radio image installed earlier to the device, and boot the device normally.

  2. Make sure you have connected the device properly.

    $ adb devices

  3. Use the adb with a push command once more to copy the contents of the recovery image package to the update.zip file in the device's SD card.

    $ adb push signed-dream_devphone_userdebug-ota-14721.zip /sdcard/update.zip

    The command prints the number of bytes copied and the elapsed time, but you should wait until the following command returns.

    $ adb shell sync

  4. Reboot the device into recovery mode by holding down the HOME key during reboot. When the device enters recovery mode, it displays a "!" icon.

  5. With the recovery console displayed, open the sliding keyboard and hold down the ALT+l key combination to enable log output in the recovery console.

  6. Next, hold down the ALT+s key combination to install the update. An installing update icon and progress bar (or a similar status message) are displayed. When the progress bar completes, the installation is finished.

  7. Press the HOME-BACK key combination to write the recovery image, update the firmware, and automatically reboot. Note that if you do not use HOME-BACK at this point, the device will not load the updated radio image. After writing the image, the device shows a updating firmware icon for a few seconds and then automatically reboots in normal mode.

Refer to this link for Japanese explanation :

Installing Java Development Kit

In Debian, you can search the available deb packages in the internet by the following command:

$ sudo aptitude search jdk

You will see Sun's official JDK and its open source version named 'openjdk' which is currently not as stable as Sun's though.

Here is the command to download and install Sun's JDK version 6 in Debian.

$ sudo aptitude install sun-java6-jdk

Installing Android SDK

Download and unpack Android SDK:

Optionally, you may want to add the location of the SDK's primary tools directory to your system PATH. The primary tools/ directory is located at the root of the SDK folder. Adding tools to your path lets you run Android Debug Bridge (adb) and the other command line tools without needing to supply the full path to the tools directory.

Add SDK components like Android Platform, documentation, and add-ons such as Google Maps API if you wish. Without an Android platform, you cannot create an AVD for any target.

Gain root access in case you have installed the SDK in a public directory, and execute the android tool command with no options.

$ sudo ..../android-sdk-linux_86/tools/android

Android SDK and AVD Manager window appears.

  1. Select Available Components in the left side. Try clicking on the box right before the default URL : https://dl-ssl.google.com/android/repository/repository.xml

  2. If it shows an error with unavailable SSL protocol, you have to create a setting in your ~/.android/androidtool.cfg file (in root's home, in this case) to force plain HTTP.

    $ sudo echo sdkman.force.http=true | sudo tee /root/.android/androidtool.cfg

    (Unfortunately it won't work clicking Add Site and entering the URL http://dl-ssl.google.com/android/repository/repository.xml using the first protocol descriptor http: instead of https: for some reason.)

  3. Bring up the Android SDK/AVD Manager again and check the box next to the URL shown above and choose Android APIs to install that are shown as the subsequent items in hierarchy.

  4. Select the components you want, e.g. Documentation for Android SDK, API4 and SDK Platform Android 1.6, API 4 for the latest platform. Click Install Selected, then check Accept All and click Install Accepted.

Installing Eclipse

If you want to use a basic integrated development environment, you need to install Eclipse IDE for Java EE Developers version 3.4 or higher (3.5 at the time of writing). Unarchive the tar.gz file and set the PATH environment variable accordingly.

Then, follow the instruction below to install Android Development Toolkit (ADT).

  1. Invoke Eclipse 3.4 or higher and choose [Help] > [Install New Software...].
  2. Press [Add...] button.
  3. Enter the URL of Android update site 'http://dl-ssl.google.com/android/eclipse/' in the Location text box.
  4. Make sure 'Developer Tools' has been added to the Available Software view.
  5. Check the box next to the Developer Tools, press [Next] button and go on.
  6. When you click on [Finish], installation will begin.
  7. If the process fails, you may want to go back and turn off the option 'Contact all update sites during install to find required software'.
  8. Restart Eclipse.

You can also refer to this documentation:

Now tell to Eclipse where you placed the SDK installation:

The SDK Location should point to the root directory of SDK installation. The path has to end with 'android-sdk-linux_x86-1.5_r3' for the version 1.5 release 3. Also choose the Target Name 'Android 1.5'.

Building the project and using the emulator

$ android list targets
$ android create avd --name [avd_name] --target [target_number]

Example :

$ android create avd -n default -t 3

In Project - Properties - Java Build Path - Order and Export, check on the latest version of Android you are using, if you get an unknown error.

Press Ctrl-F11 to flip the emulator.

Developing in other IDEs

To create a new Android project, open a command-line, navigate to the tools/ directory of your SDK and run:

$ android create project \
--target  \
--name  \
--path /path/to/your/project \
--activity  \
--package 

For example :

$ android create project -k sh.run.zzz -a zzz -t 2 -p ./zzz

To update an existing project,

$ android update project --name hiworld --target 2 --path hiworld

and a new build.xml will be created if it doesn't exist.

To build your application in debug mode for testing in, for example, the emulator, type

$ ant debug

and the build.xml will be loaded into the Android build system for building a debug-only project.

[apkbuilder] Creating .Runftp-debug.apk and signing it with a debug key...
[apkbuilder] Using keystore: /home/ryu/.android/debug.keystore

Notice the created apk is named with -debug suffix and the beggining period .. This kind of application will have expiration date of 365 days.

To make your application public, you should type

$ ant release

and the build.xml will be loaded into the Android build system for building a project that's intended to be released.

[apkbuilder] Creating .Runftp-unsigned.apk for release...

Notice the created apk is named with -unsigned suffix and the beggining period ..

$ ls -la
合計 60
drwxr-xr-x 4 ryu ryu 4096 2009-12-10 21:49 .
drwxr-xr-x 8 ryu ryu 4096 2009-12-10 21:39 ..
-rw-r--r-- 1 ryu ryu 9465 2009-12-10 21:39 .Runftp-debug.apk
-rw-r--r-- 1 ryu ryu 7912 2009-12-10 21:49 .Runftp-unsigned.apk
-rw-r--r-- 1 ryu ryu 5807 2009-12-10 21:49 .Runftp.ap_
drwxr-xr-x 3 ryu ryu 4096 2009-12-10 21:39 classes
-rw-r--r-- 1 ryu ryu 4408 2009-12-10 21:49 classes.dex
-rw-r--r-- 1 ryu ryu 5807 2009-12-07 18:46 resources.ap_
drwxr-xr-x 3 ryu ryu 4096 2009-12-07 18:46 sh

The .apk file is unsigned at this point and can't be installed until signed with your private key.

Running in Emulator

First create an Android Virtual Device with some name you like targeting the proper version of Android SDK.

$ android create avd -n default -t 3

Next, start up the emulator.

$ emulator -avd default &

Whenever the emulator is up and running, you can install your application with the debug key simply by typing :

$ ant install

Signing Your Application

The Android system uses the certificate as a means of identifying the author of an application and establishing trust relationships between applications. The certificate is not used to control which applications the user can install. The certificate does not need to be signed by a certificate authority: it is perfectly allowable, and typical, for Android applications to use self-signed certificates.

In general, the recommended strategy for all developers is to sign all of your applications with the same certificate, throughout the expected lifespan of your applications.

By signing multiple applications with the same certificate and using signature-based permissions checks, your applications can share code and data in a secure manner.

If you plan to support upgrades for your application, you should ensure that your key has a validity period that exceeds the expected lifespan of that application. A validity period of 25 years or more is recommended.

If you are developing on a version of Linux that originally came with GNU Compiler for Java, make sure that the system is using the JDK version of Keytool, rather than the gcj version. If Keytool is already in your PATH, it might be pointing to a symlink at /usr/bin/keytool. In this case, check the symlink target to make sure that it points to the Keytool in the JDK.

$ ls -l /usr/bin/keytool /usr/bin/jarsigner
lrwxrwxrwx 1 root root 27 2009-07-31 19:51 /usr/bin/jarsigner -> /etc/alternatives/jarsigner
lrwxrwxrwx 1 root root 25 2009-01-29 07:45 /usr/bin/keytool -> /etc/alternatives/keytool

Here's an example of a Keytool command that generates a private key:

$ keytool -genkey -v -keystore ryu.keystore -alias ryu
-dname "cn=Susan Miller, ou=Accounting Department, o=BlueSoft, c=us"
-keyalg RSA -validity 131072

Running the example command above, Keytool prompts you to provide passwords for the keystore and key, and to provide the Distinguished Name fields for your key. It then generates the keystore as a file called ryu.keystore. The keystore and key are protected by the passwords you entered. The keystore contains a single key, valid for 131072 days (= 359 years). The alias is a name that you — will use later, to refer to this keystore when signing your application.

To sign your application, you run Jarsigner, referencing both the application's .apk and the keystore containing the private key with which to sign the .apk.

$ jarsigner -verbose -keystore ryu.keystore my_app.apk ryu

To view the details of the signature in your application :

$ jarsigner -verify -verbose -certs my_app.apk

Maintaining the security of your private key is of critical importance, both to you and to the user. If you allow someone to use your key, or if you leave your keystore and passwords in an unsecured location such that a third-party could find and use them, your authoring identity and the trust of the user will have to be compromised.

You may choose to align your data into 4-byte boundaries for performance optimization.

$ zipalign -v 4 my_app-unaligned.apk my_app.apk

Setting up a Device for Development

With a T-mobile G1 or Android Dev Phone 1, you can develop and debug your Android applications just as you would on the emulator. There are just a few things to do before you can start.

  1. Declare your application as "debuggable" in your Android Manifest.

    In Eclipse, you can do this from the Application tab when viewing the Manifest (on the right side, set Debuggable to true). Otherwise, in the AndroidManifest.xml file, add android:debuggable="true" to the <application> element.

  2. Turn on "USB Debugging" on your device.

    On the device, go to the home screen, press MENU, select Applications > Development, then enable USB debugging.

You can verify that your device is connected by executing adb devices from your SDK tools/ directory. If connected, you'll see the device name listed as a "device."

If using Eclipse, select run or debug as usual. You will be presented with a Device Chooser dialog that lists the available emulator(s) and connected device(s). Select the device to install and run the application there.

If using the Android Debug Bridge (adb), you can issue commands with the -d flag to target your connected device.

Running in Device

You can use adb to copy an application from your development computer and install it onto the device.

$ sudo ..../android-sdk-linux_86/tools/adb install hogehoge.apk

If it errors out with insufficient permissions, ensure you have started the adb daemon as root.

Select the installed application from the application launcher menu and it will execute in Android OS.

Activities, Tasks and Affinities

Activities defined in different applications can share an affinity, or activities defined in the same application can be assigned different affinities. The affinity comes into play in two circumstances: When the Intent object that launches an activity contains the FLAG_ACTIVITY_NEW_TASK flag, and when an activity has its allowTaskReparenting attribute set to "true".

If an .apk file contains more than one "application" from the user's point of view, you will probably want to assign different affinities to the activities associated with each of them.

Threads

Since the user interface must always be quick to respond to user actions, the thread that hosts an activity should not also host time-consuming operations like network downloads. Anything that may not be completed quickly should be assigned to a different thread.

Icons

Android application icons are created with general image editing tools like GIMP or ImageMagick. The image size is 48x48 pixels and the format is PNG.

References


Have fun.

Ryu ryu@run.sh