When the Choose Widget dialog box is visible, choose Silent Mode Toggle, as shown in Figure 7-6.

188 Part II: Building and Publishing Your First Android Application your application so that it can be placed on end users’ devices. To do so, you create an Android package file, also known as an APK file. In the following sections, I guide you through the process of creating your first APK file. Revisiting the manifest file Before you jump in and create the distributable APK file, you should take great care to make sure that your application is available to as many users as possible. This is done by getting very familiar with the uses-sdk element in the AndroidManifest.xml file. Your AndroidManifest.xml file currently has a uses-sdk entry that was created in Chapter 4: uses-sdk android:minSdkVersion=”4” The minSdkVersion property identifies which versions of the Android plat- form can install this application. In this instance, level 4 has been selected. The Silent Mode Toggle application was developed by setting the target soft- ware development kit SDK to version 8. Wait, I know, I’m using version 4 as the minimum SDK but I’m telling Eclipse and Android that I’m targeting the version 8 SDK. How can all this madness work? The Android platform, for the most part, is backward compatible. Most all the features that are in version 3 are also in version 4. Yes, small changes and sometimes new large components are released in each new version, but for the most part, everything else in the platform remains backward compatible. Therefore, stating that this application needs a minimum of SDK version 4 signifies that any Android operating system that is of version 4 or greater can run the application. Using the minSdkVersion information, the Android Market can determine which applications to show each user of each device. If you were to release the application right now with minSdkVersion set to the value of 4, and you opened the Android Market on an Android device running version 3 Android 1.5 or lower, you would not be able to find your application. Why? The Android Market filters it out for you. You, the developer, told the Android Market, “Hey This app can only run on devices that are of API Level 4 or greater” If you were to open the Android Market on a device running API Level 4 or above, you would be able to find and install your application. If you do not provide a minSdkVersion value in the uses-sdk element of the application’s manifest, the Android Market defaults the minSdkVersion to 0, which means that this application is compatible with all versions of Android. If your application happens to use a component not available in older versions of the platform such as the Bluetooth technology in Android 2.0 and a user installs your application, he or she receives a run-time error informing the user that the application could not continue because an exception occurred. 189

Chapter 8: Publishing Your App to the Android Market

Choosing your tools You can build an Android APK file in numerous ways: ✓ Through the Android Development Tools ADT inside Eclipse ✓ Via an automated build process, like a continuous integration server, such as Hudson Continuous Integration Server ✓ Via the command line with Ant ✓ Via the Maven build system You use the ADT within Eclipse to create your APK file. The ADT provides an array of tools that compiles, digitally signs, and packages your Android appli- cation into an APK file. In that process, the digital signature process takes place; this is discussed in the next section. The other options, such as Ant and continuous integration, are possible but are used in more advanced scenarios. You can find more information about setting up an Ant build process to use in these types of build mechanisms in the Android documentation at http:d.android.comguide publishingapp-signing.html. Digitally signing your application The Android system requires that all installed applications be digitally signed with a certification that contains a publicprivate key pair. The private key is held by the developer. The certification that is used to digitally sign the appli- cation is used to identify the application, and the developer is used for estab- lishing the trust relationships between applications. You need to know a few key things about signing Android applications: ✓ All Android applications must be signed. The system will not install an application that is not signed. ✓ You can use self-signed certificates to sign your applications; a certificate authority is not needed. ✓ When you are ready to release your application to the market, you must sign it with a private key. You cannot publish the application with the debug key that signs the APK file when debugging the application during development. ✓ The certificate has an expiration date, and that expiration date is only verified at install time. If the certificate expires after the application has been installed, the application will continue to operate normally.