First Steps in Android
-
Upload
rich-helton -
Category
Technology
-
view
1.267 -
download
0
description
Transcript of First Steps in Android
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android (Java)
First Steps(By Rich Helton)
Android (Rev 1)
State of ColoradoOffice of Cyber Security
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android
From http://en.wikipedia.org/wiki/Android_(operating_system), Android is a software stack for mobile devices that includes an operating system, middleware and key applications. Androids mobile operating system is based on the Linux kernel. The Android open-source software stack consists of Java applications running on a Java-based, object-oriented application framework on top of Java core libraries running on a Dalvik virtual machine JIT compilation. To me, Android is a Java framework with many underlying C libraries that run in an embedded Linux environment. As an embedded system, there are many performance and memory constraints based on hardware of a mobile device.
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android pieces
For Database work, Android comes with a stripped down database server called SQLite, which is an embedded relational database management system. http://en.wikipedia.org/wiki/SQLite and www.sqlite.org For Animation, OpenGL ES (Embedded Systems), is used for 3D and 2D graphics applications, http://en.wikipedia.org/wiki/OpenGL_ES For the Android User Interface, the system uses a comparable RIA interface using the XML User Interface Language (XUL). There are many other packages that will be discussed later, including the REST interface for WebServices, Telephony API, Search API, Google Maps and more.
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Manifest
The Android Manifest file is an XML file that will define your Android application’s resources. It is similar to a J2EE web.xml file. Every Android application has one that will define many pieces to your application including images, permissions, UI pieces, and much more. See http://developer.android.com/guide/topics/manifest/manifest-intro.html
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Manifest
A sample manifest file in Eclipse:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android APK
Android will compile its project, including the manifest, into a APK file to run on the device, see http://en.wikipedia.org/wiki/APK_(file_format)
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Technical Resources
Various Sample applications can be found at http://developer.android.com/resources/browser.html?tag=sample A resource of Common tasks and how to do them in Android http://developer.android.com/resources/faq/commontasks.html such as displaying Alert Dialogs or Handling UI Events.
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Development
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Development
To start Android development, the Java Development Kit needs to be installed locally. Depending on the local development environment will dictate which JDK to use. After installing the JDK, you should install the Eclipse IDE, the most popular cross platform IDE for Java development, http://en.wikipedia.org/wiki/Eclipse_(software) I like to use the Helios Eclipse for Java Developers http://www.eclipse.org/downloads/ Installing the SDK can be found at http://developer.android.com/sdk/installing.html
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Development
After installing Helios, the Android Development Toolkit can be installed as a plugin by using the the Help Menu-> Install New Software and Add https://dl-ssl.google.com/android/eclipse :
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Development
Instead of using the Eclipse IDE, command line development can be done using the Android Software Development Kit (SDK). The SDK can be installed, or downloaded, from http://developer.android.com/sdk/index.html After installation, you will have a Android SDK and AVD Manager to manage the build packages and virtual devices:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Development
The Eclipse IDE needs to point to the Android SDK packages, using Windows->Preferences->Android:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Virtual Device (AVD)
An AVD will have to be created for debugging, this is your target device, http://developer.android.com/resources/tutorials/hello-world.html
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Development
Let’s start a New Android in Eclipse, File -> New->Project, http://developer.android.com/guide/developing/projects/projects-eclipse.html :
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Development
A basic “HelloWorld” project:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Development
A basic “HelloWorld” project in just the SDK, no Eclipse, from the SDK command line:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Development
Create some code, like showing a TextView with “Hello World”:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Development
Select Run-Run, select “Android Application” and wait for the emulator to start:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Development
It prints:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Emulator
In order to debug/run an Android application, a Android emulator, to simulate a virtual phone will need to be set up through the ADT. See http://developer.android.com/guide/developing/tools/emulator.html A hardware device can also be used, http://developer.android.com/guide/developing/device.html
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android UI
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android UI
As mentioned earlier, XUL can be used to define the Android UI, instead of programmatic code like the previous TextView class. Let’s look an example of XUL, using DroidDraw from http://droiddraw.org/ we can draw a UI and generate the XML:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Droid Draw
Showing TextView in DroidDraw:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
The View
The are several components to the UI. One component is the View. TextView is derived from View. The View class represents the basic building block for the interface components. http://developer.android.com/reference/android/view/View.html The View can be part of ViewGroup, and needs to have defined layout http://developer.android.com/guide/topics/ui/index.html A Layout will define how the View will display its objects, or widgets, http://developer.android.com/guide/topics/ui/layout-objects.html The layout is the architecture for the UI in an Activity. It will define how the elements appear to the user, http://developer.android.com/guide/topics/ui/declaring-layout.html
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Hello, Views
http://developer.android.com/resources/tutorials/views/index.html contains a collection of different “Hello World” tutorials in various layouts. An example is the Grid View, which displays items in a two-dimensional, scrollable grid. http://developer.android.com/resources/tutorials/views/hello-gridview.html Others include Linear Layouts, Relatove Layout, Table Layout, Tab Layout, and List Views. There are also tutorials for widgets like Date Picker, Time Picker, Google Maps, Web View, Gallery, Spinner, Form Stuff and Auto Complete.
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Droid Draw
Using Droid Draw to display a Table Layout with a GridView and Radio Buttons:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
The Emulator
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
The Emulator
Using the Emulator http://developer.android.com/guide/developing/devices/emulator.html There are several ways to interface to the Emulator, DDMS, ADB, and telnet.
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Package Browser
Menu->Package Browser
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Telnetting
Telnet from the local machine “telnet localhost 5554”:
“help” for the commands:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Make a call through telnet
“gsm call 3031234” :
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
DDMS
The Eclipse DDMS can attach to a running emulator (Start Eclipse first), and just explore the files:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
DDMS call
Make a call through DDMS, http://developer.android.com/guide/developing/debugging/ddms.html :
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
WebView and WebKit
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Webkit.WebView
Adding items to the Screen Menu http://developer.android.com/resources/faq/commontasks.html#filelist
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
SQLite
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
SQLite
Android comes preconfigured with a embedded version of SQLite, http://www.sqlite.org/ There are several GUI tools that can be used to administrate SQLite database, included http://sqliteman.com/ the GUI for SQLite 3. The database itself can be examined through adb as a remote shell http://developer.android.com/guide/developing/tools/adb.html#sqlite The Notepad Tutorial , Exercise 1, uses SQLite to store notes http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Debugging
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Debugging
Debugging information can be found at http://developer.android.com/guide/developing/debugging/index.html Android is shipped with the Dalvik Debug Monitor Server (DDMS), which provides port-facing services, screen capture on the device, thread and heap information, logcat, and much more. http://developer.android.com/guide/developing/debugging/ddms.html Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. http://developer.android.com/guide/developing/tools/adb.html TraceView is a graphical viewer for execution logs that you create using the Debug class to log tracing information in your code. http://developer.android.com/guide/developing/debugging/debugging-tracing.html
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
DDMS
From Eclipse, select Windows->Open Perspective->Other -> DDMS:
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
DDMS
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
ADB
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
ADB
The Android Debug Bridge (ADB), http://developer.android.com/guide/developing/tools/adb.html
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
ADB Shell
ADB can run a shell into the emulator, or remote device, here’s the databases, “ls –R /data/data/*/databases” :
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
ADB install
Installing APK applications, “abd –s emulator-554 install” :
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Notepad Tutorial
CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE
State of Colorado Office of Cyber Security
Android Tutorial
There is a popular tutorial to walk the programmer through many of the features of Android called the Notepad Tutorial, http://developer.android.com/resources/tutorials/notepad/index.html