Sunday, July 06, 2014

Designing Programming the Android SDK - Part 2

Go back - Designing Programming the Android SDK - Part 1

Android Emulator Set-up

The easiest way to setup an Android Emulator is in Eclipse.

1) Click the window menu, then click on Android Virtual Device Manager.
2) Click the Device Definitions tab.
3) Click on one of the pre-setup device definitions, e.g. Nexus S or Nexus One. Then click the “Create AVD...” button. Then click the “OK” button from the Create new AVD window that pops-up.

Then the new AVD should appear on the Android Virtual Device Manager screen. Then you may close the AVD Manager screen. The Android Virtual Device (AVD) has been set-up.

Test running our app for the first time

If you have an Android device that you want to use during testing, you can plug it into the computer. You will want to go to the settings on your device and find the Development options in the Applications list item. Click the check box next to USB debugging. This will allow you install apps onto your phone in debug mode through the USB cable. You may also need the driver that came with your device to set-up your device to work with your computer properly.

If you don’t want to use your Android device or if you don’t have one to test with, you can use the Emulator that we just set-up.

There are three different ways to run the app in the emulator or on the device – they all do the same thing, so use whichever is most convenient for you.
1) Right click on the project in the Package Explorer, go to Run As, then click Android Application.
2) Click run under the run menu and then choose Android Application and click OK.
3) Click on the green button in the toolbar that looks like a play button with a white arrow in the center, then choose Android Application and click OK.

The process for the app to install on a device (Virtual or Physical) should now begin. Be aware that starting an Emulator is like booting-up a phone – the process usually takes a few minutes. So be patient. Your app should appear on the device with the words on the screen from the strings.xml file.

Congratulations, you have just created your first app.

But we are not done yet, we have to export our app for other people to be able to use it and after that we are going to add a little more functionality into our app.

Exporting the App

To export our app for other people to use, we click on Export in Eclipse either by going to the File menu or by right clicking on our project in the Package Explorer. Clicking Export in Eclipse will bring up the Export Wizard.

The first step in the Export Wizard is to select Export Android Application from within the Android folder. After clicking next we have to choose the project we want to export. Clicking next brings us to the Keystore selection page.

In order for us to export our app for other people to use, we have to first create a Keystore that we will use to sign our app. So click on the Create New Keystore radio button. Select a location and name for the Keystore file. Note that you should keep this in an easy to find place as it is a good idea to use the same Keystore to sign all of your apps. Enter a password for the Keystore twice and click the next button. Now enter in information for the fields on the page: Alias is just an alternative name for the Keystore; enter your password twice; for the Validity (years) field enter in at least 25; then enter in your name, organizational unit, organization, city or locality, state or province and country.

Clicking next brings up a screen that asks where you would like to save the app. So choose a destination on your computer and click Finish.

Now your app is in a format where it can be installed on any compatible Android device. An easy way to install the app on a phone is to email it to a gmail account that is set-up on an Android device. From gmail you can install .apk attachments onto a device after the user of the device has checked the “Allow installation of non-Market applications” setting.

The next time you export an Android app, you can use the same Keystore you just created, saving a step.

Great, we have an Android app that we can install onto virtually any Android device. So let’s add a little more functionality into our app to make it more exciting.

Read Next - Designing Programming the Android SDK - Part 3

No comments: