First Steps in Android

Download First Steps in Android

Post on 14-May-2015

1.251 views

Category:

Technology

0 download

DESCRIPTION

Starting in Android

TRANSCRIPT

  • 1.CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Android (Java)First Steps(By Rich Helton)Android (Rev 1) State of ColoradoOffice of Cyber SecurityState of Colorado Office of Cyber Security

2. AndroidCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE From http://en.wikipedia.org/wiki/Android_(operating_system), Android is a software stack for mobile devices that includes anoperating system, middleware and key applications. Androids mobile operating system is based on the Linux kernel. The Android open-source software stack consists of Javaapplications running on a Java-based, object-oriented applicationframework on top of Java core libraries running on a Dalvik virtualmachine JIT compilation. To me, Android is a Java framework with many underlying Clibraries that run in an embedded Linux environment. As anembedded system, there are many performance and memoryconstraints based on hardware of a mobile device.State of Colorado Office of Cyber Security 3. Android piecesCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE For Database work, Android comes with a stripped down databaseserver called SQLite, which is an embedded relational databasemanagement system. http://en.wikipedia.org/wiki/SQLite andwww.sqlite.org For Animation, OpenGL ES (Embedded Systems), is used for 3Dand 2D graphics applications,http://en.wikipedia.org/wiki/OpenGL_ES For the Android User Interface, the system uses a comparable RIAinterface 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.State of Colorado Office of Cyber Security 4. Android ManifestCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE The Android Manifest file is an XML file that will define yourAndroid applications resources. It is similar to a J2EE web.xml file. Every Android application has one that will define many pieces toyour application including images, permissions, UI pieces, and muchmore. Seehttp://developer.android.com/guide/topics/manifest/manifest-intro.htmlState of Colorado Office of Cyber Security 5. Android ManifestCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE A sample manifest file in Eclipse:State of Colorado Office of Cyber Security 6. Android APKCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Android will compile its project, including the manifest, into a APKfile to run on the device, seehttp://en.wikipedia.org/wiki/APK_(file_format)State of Colorado Office of Cyber Security 7. Technical ResourcesCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Various Sample applications can be found athttp://developer.android.com/resources/browser.html?tag=sample A resource of Common tasks and how to do them in Androidhttp://developer.android.com/resources/faq/commontasks.html suchas displaying Alert Dialogs or Handling UI Events.State of Colorado Office of Cyber Security 8. CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Android DevelopmentState of Colorado Office of Cyber Security 9. Android DevelopmentCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE To start Android development, the Java Development Kit needs tobe installed locally. Depending on the local development environmentwill dictate which JDK to use. After installing the JDK, you should install the Eclipse IDE, the mostpopular cross platform IDE for Java development,http://en.wikipedia.org/wiki/Eclipse_(software) I like to use the Helios Eclipse for Java Developershttp://www.eclipse.org/downloads/ Installing the SDK can be found athttp://developer.android.com/sdk/installing.htmlState of Colorado Office of Cyber Security 10. Android DevelopmentCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE After installing Helios, the Android Development Toolkit can beinstalled as a plugin by using the the Help Menu-> Install NewSoftware and Add https://dl-ssl.google.com/android/eclipse :State of Colorado Office of Cyber Security 11. Android DevelopmentCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Instead of using the Eclipse IDE, command line development canbe done using the Android Software Development Kit (SDK). The SDK can be installed, or downloaded, fromhttp://developer.android.com/sdk/index.html After installation, you will have a Android SDK and AVD Manager tomanage the build packages and virtual devices:State of Colorado Office of Cyber Security 12. Android DevelopmentCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTUREThe Eclipse IDE needs to point to the Android SDK packages, usingWindows->Preferences->Android:State of Colorado Office of Cyber Security 13. Android Virtual Device (AVD)CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTUREAn AVD will have to be created for debugging, this is your targetdevice,http://developer.android.com/resources/tutorials/hello-world.htmlState of Colorado Office of Cyber Security 14. Android DevelopmentCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Lets start a New Android in Eclipse, File -> New->Project,http://developer.android.com/guide/developing/projects/projects-eclipse.html:State of Colorado Office of Cyber Security 15. Android DevelopmentCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE A basic HelloWorld project:State of Colorado Office of Cyber Security 16. Android DevelopmentCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE A basic HelloWorld project in just the SDK, no Eclipse, from theSDK command line:State of Colorado Office of Cyber Security 17. Android DevelopmentCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Create some code, like showing a TextView with Hello World:State of Colorado Office of Cyber Security 18. Android DevelopmentCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Select Run-Run, select Android Application and wait for theemulator to start:State of Colorado Office of Cyber Security 19. Android DevelopmentCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE It prints:State of Colorado Office of Cyber Security 20. Android EmulatorCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE 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.Seehttp://developer.android.com/guide/developing/tools/emulator.html A hardware device can also be used,http://developer.android.com/guide/developing/device.htmlState of Colorado Office of Cyber Security 21. CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Android UIState of Colorado Office of Cyber Security 22. Android UICYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE As mentioned earlier, XUL can be used to define the Android UI,instead of programmatic code like the previous TextView class. Lets look an example of XUL, using DroidDraw fromhttp://droiddraw.org/ we can draw a UI and generate the XML:State of Colorado Office of Cyber Security 23. Droid DrawCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Showing TextView in DroidDraw:State of Colorado Office of Cyber Security 24. The ViewCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE 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 interfacecomponents.http://developer.android.com/reference/android/view/View.html The View can be part of ViewGroup, and needs to have definedlayout http://developer.android.com/guide/topics/ui/index.html A Layout will define how the View will display its objects, orwidgets,http://developer.android.com/guide/topics/ui/layout-objects.html The layout is the architecture for the UI in an Activity. It will definehow the elements appear to the user,http://developer.android.com/guide/topics/ui/declaring-layout.htmlState of Colorado Office of Cyber Security 25. Hello, ViewsCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE http://developer.android.com/resources/tutorials/views/index.htmlcontains a collection of different Hello World tutorials in variouslayouts. 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 AutoComplete.State of Colorado Office of Cyber Security 26. Droid DrawCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Using Droid Draw to display a Table Layout with a GridView andRadio Buttons:State of Colorado Office of Cyber Security 27. CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE The EmulatorState of Colorado Office of Cyber Security 28. The EmulatorCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Using the Emulatorhttp://developer.android.com/guide/developing/devices/emulator.html There are several ways to interface to the Emulator, DDMS, ADB,and telnet.State of Colorado Office of Cyber Security 29. Package BrowserCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Menu->Package BrowserState of Colorado Office of Cyber Security 30. TelnettingCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Telnet from the local machine telnet localhost 5554:help for the commands:State of Colorado Office of Cyber Security 31. Make a call through telnetCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE gsm call 3031234 :State of Colorado Office of Cyber Security 32. DDMSCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE The Eclipse DDMS can attach to a running emulator (Start Eclipsefirst), and just explore the files:State of Colorado Office of Cyber Security 33. DDMS callCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Make a call through DDMS,http://developer.android.com/guide/developing/debugging/ddms.html :State of Colorado Office of Cyber Security 34. CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE WebView and WebKitState of Colorado Office of Cyber Security 35. Webkit.WebViewCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Adding items to the Screen Menuhttp://developer.android.com/resources/faq/commontasks.html#filelistState of Colorado Office of Cyber Security 36. CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE SQLiteState of Colorado Office of Cyber Security 37. SQLiteCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Android comes preconfigured with a embedded version of SQLite,http://www.sqlite.org/ There are several GUI tools that can be used to administrateSQLite database, included http://sqliteman.com/ the GUI for SQLite 3. The database itself can be examined through adb as a remote shellhttp://developer.android.com/guide/developing/tools/adb.html#sqlite The Notepad Tutorial , Exercise 1, uses SQLite to store noteshttp://developer.android.com/resources/tutorials/notepad/notepad-ex1.htmlState of Colorado Office of Cyber Security 38. CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE DebuggingState of Colorado Office of Cyber Security 39. DebuggingCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Debugging information can be found athttp://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 thatlets you communicate with an emulator instance or connectedAndroid-powered device.http://developer.android.com/guide/developing/tools/adb.htmlTraceView is a graphical viewer for execution logs that you createusing the Debug class to log tracing information in your code.http://developer.android.com/guide/developing/debugging/debugging-tracingState of Colorado Office of Cyber Security 40. DDMSCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE From Eclipse, select Windows->Open Perspective->Other ->DDMS:State of Colorado Office of Cyber Security 41. DDMSCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTUREState of Colorado Office of Cyber Security 42. CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE ADBState of Colorado Office of Cyber Security 43. ADBCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE The Android Debug Bridge (ADB),http://developer.android.com/guide/developing/tools/adb.htmlState of Colorado Office of Cyber Security 44. ADB ShellCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE ADB can run a shell into the emulator, or remote device, heres thedatabases, ls R /data/data/*/databases :State of Colorado Office of Cyber Security 45. ADB installCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTUREInstalling APK applications, abd s emulator-554 install :State of Colorado Office of Cyber Security 46. CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE Android Notepad TutorialState of Colorado Office of Cyber Security 47. Android TutorialCYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE HOMELAND SECURITY MULTI-USER NETWORK CYBER SECURITY INFORMATION TECHNOLOGY CRITICAL INFRASTRUCTURE There is a popular tutorial to walk the programmer through many ofthe features of Android called the Notepad Tutorial,http://developer.android.com/resources/tutorials/notepad/index.htmlState of Colorado Office of Cyber Security