Android Programming Workshop22313

128
Android Development Course Ahmad Hanis 1

description

Android workshop

Transcript of Android Programming Workshop22313

  • Android Development CourseAhmad Hanis*

  • What Is AndroidAndroid is the operating system that controls phones, tablets and many other devices. An operating system is the core of the device and helps applications communicate with various hardware components. It also provides a uniform user-interface to allow you to interact with the device and applications that run on the device.*

  • Where it came fromAndroid was the development of Android Inc., started in 2003 in Palo Alto, California. In 2005 Google, acquired Android, Inc. and the development team behind Android. The core of Android is based on LinuxThe Android OS was officially announced at the end of 2007 and in 2008 Google made Android available under an open source code license. This means manufacturers and carriers can use and modify Android without a licensing payment, making a lower cost and more flexible solution for many companies.*

  • Why Mobile App Development?The fact that we can! Only a few years ago you had to be in the Motorola inner circle to do it!Mobile platform is the platform of the futureDouble-digit growth in world-wide smartphone ownership3Job market is hotMarket for mobile software surges from $4.1 billion in 2009 to $17.5 billion by 20122012 Dice.com more than 68130 open job available every day.Dice.com: mobile app developers made $92,000 in 2012and salaries expected to riseStudents (and faculty!) are naturally interested!*

  • Why Android?A lot of people have them70% of worldwide market shareStudents already know Java and EclipseLow learning curveBIT students can use App Inventor for Android1http://testkitchen.colorado.edu/projects/reports/smartphone/smartphone-appendix1/2http://www.gartner.com/it/page.jsp?id=1543014*

  • Android Operating System*

  • Android DevicesPhone Tablet E-ReadersOthers*

  • Android-Powered Microwavehttp://www.pocket-lint.com/news/30712/android-powered-microwave-cooking-googleBy Touch Revolution at CES 2010*

  • Brief History1996The WWW already had websites with color and imagesBut, the best phones displayed a couple of lines of monochrome text!Enter: Wireless Application Protocol (WAP) stripped down HTTP for bandwidth reductionWireless Markup Language (WML) stripped down HTML for content

    *

  • Brief HistoryMany issues (WAP = Wait And Pay)Few developers to produce content (it wasnt fun!)Really hard to type in URLs using the small keyboardsData fees frightfully expensive No billing mechanism content difficult to monetizeOther platforms emergedPalm OS, Blackberry OS, J2ME, Symbian (Nokia), BREW, OS X iPhone, Windows Mobile*

  • Brief History - Android2005Google acquires startup Android Inc. to start Android platformWork on Dalvik VM begins2007Open Handset Alliance announcedEarly look at SDK2008Google sponsors 1st Android Developer ChallengeT-Mobile G1 announcedSDK 1.0 releasedAndroid released open source (Apache License)Android Dev Phone 1 released

    *

  • Brief History cont.2009SDK 1.5 (Cupcake)New soft keyboard with autocomplete featureSDK 1.6 (Donut)Support Wide VGA SDK 2.0/2.0.1/2.1 (Eclair)Revamped UI, browser2010Nexus One released to the publicSDK 2.2 (Froyo)Flash support, tetheringSDK 2.3 (Gingerbread)UI update, system-wide copy-paste

    *

  • The Android Developer Websitehttp://developer.android.com/index.html

    This should be your homepage for the next semester! *

  • Distribution of Devices

    *

  • What is Google Android?A software stack for mobile devices that includesAn operating systemMiddlewareKey Applications

    Uses Linux to provide core system servicesSecurityMemory managementProcess managementPower managementHardware drivers*

  • Android ArchitectureMore details at: http://developer.android.com/guide/basics/what-is-android.html *

  • Mobile Devices: Advantages (as compared to fixed devices)Always with the userTypically have Internet accessTypically GPS enabledTypically have accelerometer & compassMost have cameras & microphonesMany apps are free or low-cost

    *

  • Mobile Devices: DisadvantagesLimited screen sizeLimited battery lifeLimited processor speedLimited and sometimes slow network accessLimited or awkward input: soft keyboard, phone keypad, touch screen, or stylusLimited web browser functionalityRange of platforms & configurations across devices

    *

  • Mobile ApplicationsWhat are they?Any application that runs on a mobile deviceTypesWeb apps: run in a web browserHTML, JavaScript, Flash, server-side components, etc.Native: compiled binaries for the deviceOften make use of web services*

  • Android AppsBuilt using Java and new SDK librariesNo support for some Java libraries like Swing & AWTOracle currently suing Google over useJava code compiled into Dalvik byte code (.dex)Optimized for mobile devices (better memory management, battery utilization, etc.)Dalvik VM runs .dex files

    *

  • Building and running

    ADB is a client server program that connects clients on developer machine to devices/emulators to facilitate development.An IDE like Eclipse handles this entire process for you.

    http://developer.android.com/guide/developing/building/index.html#detailed-buildCompiled resources (xml files)Android Debug Bridge*

  • Applications Are BoxedBy default, each app is run in its own Linux processProcess started when apps code needs to be executedThreads can be started to handle time-consuming operationsEach process has its own Dalvik VMBy default, each app is assigned unique Linux IDPermissions are set so apps files are only visible to that app*

  • Android Architecture*

  • Publishing and MonetizingPaid apps in Android Market, various other marketsFree, ad-supported apps in Android MarketAd networks (Google AdMob, Quattro Wireless)Sell your own adsServices to other developersEx. Skyhook Wireless (http://www.skyhookwireless.com/) Contests (Android Developer Challenge)Selling products from within your app

    *

  • Android Markethttp://www.android.com/market/

    Has various categories, allows ratingsHave both free/paid appsFeatured apps on web and on phoneThe Android Market (and iTunes/App Store) is great for developers Level playing field, allowing third-party appsRevenue sharing*

  • Publishing to Android MarketRequires Google Developer Account$25 feeLink to a Merchant AccountGoogle CheckoutLink to your checking accountGoogle takes 30% of app purchase price*

  • *

  • Android Design PhilosophyApplications should be:FastResource constraints:
  • Other design principleshttp://developer.android.com/design/index.html

    Great reference!*

  • Apple vs. GoogleOpen Handset Alliance30+ technology companiesCommitment to openness, shared vision, and concrete plansCompare with Mac/PC battlesSimilar (many PC manufacturers, one Apple)Different (Microsoft sells Windows, Google gives away Android)*

  • Android Development*

  • Android DevelopmentAndroid Development Life CycleSetting up Eclipse + SDK + JDK + ADBHelloWorld Your First ProgramHello World DemystifyGUI Layout & Java CodesButton ActionMath OperationLayout Selection*

  • Development process for an Android apphttp://developer.android.com/guide/developing/index.html *

  • (1-a) Setup Dev Environment!!Long wayInstall JDK and set pathInstall EclipseInstall Android SDKDownload Android API through SDK ManagerConfigure Eclipse + Android SDKInstall Android Device Driver (Optional)*

  • Setup Dev Environment!!Shorter wayInstall JDK - Available from C:\AndroidSDK-bundleEclipse-4win-x86\Tools\jdk-7u3-windows-i586)Copy AndroidSDK-bundleEclipse-4win-x86 folder to your C:\ directoryRun Eclipse for the first time to check the SDK integrationSet your workspaceyou should get

    *

  • Setup Dev Environment!!If not then proceed with SDK configuration.Go to Window Preferences and set the SDK locationYou should get *

  • Setup Dev Environment!!Finally to verify your configuration check your android SDK manager from window menu.Your SDK API already preinstalled with API 17 and 10You can download any API youre interested using the SDK manager.*

  • Setup Dev Environment!!Java Path If you use the bundled android development package, the java build path has been predefined in the eclipse preferences.To check if the java path has been define properly go to menu Window Select Preferences. *

  • (1-b)Setup AVD & Device for TestingYour compiled android application can run on:AVD Android Virtual DeviceVirtual device that simulate android operating systemDriver - Physical Android DeviceDirectly compiled to the device*

  • (1-b) Setup AVD & Device for TestingAVD Android Virtual Device SetupWindow Android Virtual Device ManagerNew Enter AVD name Target API OKSelect AVD and click start

    *

  • (1-b) Setup AVD & Device for TestingTips on AVDMake sure to select the right API level for your application.Choose the device resolution as low as possible to improve simulator performance.Leave the AVD open through out the application development process. *

  • (2) Development Hello World(2-a) Hello World Your first android application!!!zero programming requiredStep 1Step 2*

  • (2) Development - Hello WorldStep 3Step 4*

  • (2) Development Hello WorldStep 5Step 6*

  • (2) Development Hello World*

  • (2) Development Hello WorldRunning Hello World application on your AVDDo not change anything to the java codes and xml interface!!!To compile and run your program on AVD:

    Step 1 Click run buttonStep 2 Run as Android Apps*

  • (2) Development - Hello WorldStep 3 Select AVD ProfileStep 4 Hello World Run*

  • (2) Development- DemystifyAndroid Development ExplainedTwo main programming componentXML Interface Layout (Activity)Java code for activity

    *

  • (2) Development - DemystifyGraphical Interface Layout*

  • (2) Development - DemystifyActivity_main.xml*

  • (2) Development - DemystifyEach object in the layout has it own XML code that describe its properties.Object properties can be change by using the properties window*

  • (2) Development - DemystifyAutomatically created for every new projectLink with activity *

  • Exercise 1Simple Java Program that add a text to the textview.Create new android program and give a name Android Text.Add android:id=@id/textView1 in activity_main.xml file or using you can use the textview properties*

  • (2-b) DevelopmentDouble click on your MainActivity.java and add the following code to the existing code:Noticed the redline under TextView. *

  • (2-b) DevelopmentThis error indicate missing package. To import missing package place the cursor on the error text and click import TextView (android.widget)Run the code on your emulator*

  • (2-b) DevelopmentTextview hard coded with and show on the screen.*

  • Exercise 2Add two more textview and put your name and matric number for each textview respectively using the java codes.*

  • ExplanationTextView = class (Need to import this class first before use)teks = object you can use any legal programming namesetText = operation that can be performed.*

  • Development Button ClickCreate new project and give a name as Button HandlerChange Form Layout to Linear Layout.Insert TextView,editText1,bbutton1 and textView1(large) to the form layout.

    *

  • Development Button Click4. Run the interface on your AVD and you should get 5. To add Button operation you need to create a method that describe the action of the button.6. Access your Activity_main.xml and look for Button configuration

    *

  • Development Button Click7. Add the following line to the button xml configuration.8. handleClick is basically the name of the method that will be use in MainActivity.java9. You can use any name as long as it follows the programming naming convention.*

  • Development Button Click10. Open your MainActivity.java and add the handleClick method to the class. 11. Follow exactly as in this page. Make sure location of the method is correct!!!*

  • Development Button Click11.Run the code on your AVD and insert a text and press a button*

  • ExplanationCan you see the repetition and logic behind android programming.For every widget/component in the layout, it need to have the reference in java code. Then object can perform operation from selected method.

    *

  • Development String ManipulationIn this exercise we are going to use our previous project (Button Click)Modify the handleClick method as follow:

    Run the project*

  • Development String ManipulationThe result of string manipulation where your name is printed in reverse.The use of build method reverse for string manipulation allow the input string to reverse it content.*

  • Development String Manipulation advance Further modify your handleClick method with the following codes*

  • Development String Manipulation advance Assignment!!!The codes given is incomplete!!!. Complete the code so that the output from pressing the button should display as in the figure *

  • Development Number Manipulation1. Start a new project and name it Temperature Converter2. Change the form layout to linear layout3. Design the form layout as in the figure 4. Run the form on your AVD5. Add handleNom method to your xml file. (where and how??)

    *

  • Development Number Manipulation6. Add the handleNom method to your java code. (where and how??)7. Run the program on your AVD.

    *

  • Exercise BMI CalculatorDevelop a BMI calculator using the following formula and provide output based on the scale.*

  • Exercise BMI CalculatorYou should get the output like this *

  • Exercise - Modify BMITo add image for each result

    Hide softkeyboard

    Input2=one of the edittext object in your javaModify your EditText android:inputType properties so that only numbered softkeyboard will appear

    *

  • Finally You Should GetFinal Version

    *

  • Date PickerCreate a new project name Date HandlerDesign your form as Create a handleDate method in your java fileAdd handleDate onclick to your activity form.xml.*

  • Exercise Date formatterModify your layout as this Modify your dateHandler method with the following codes.*

  • Exercise Date formatter*

  • Input ControlCheck BoxCreate new project called Input ControlAdd two check box in the formCreate onCheckboxClicked method in the java code

    *

  • Input ControlRadio ButtonAdd two radio button to the form.Group both radio button in the xml layout.

    Add the following methods codes to java*

  • Input ControlToggle ButtonModify your current project by adding toggle button to your xml layout Add the onToggleClicked method to java class

    *

  • Input ControlSpinner (dropdown combo)Add spinner to your current projectTo populate spinner with data go to package explorer and access the value directory strings.xmlAdd new string array *

  • Input ControlGo back to your interface xml layout and select spinner.Go to spinner propertiesSelect Entries and choose planet_array from Reference ChooserRun the code*

  • Input ControlResponding from user select item from spinner*

  • Input controlModify codes in the main class*

  • Input ControlSeekbar Add Seekbar to the layoutAdd the following to string.xml

    Add following xml to seekbar layout

    *

  • Input ControlAdd the following java codes*

  • Create MenuTo create new menu access the activity_main.xml under the res/menu folderAccess the xml code and add new menu by adding item tag under menu tag.*

  • Create MenuMenu operation can be perform by adding the following method*

  • Alert DialogAdd a button and set the onClick properties to clickAlert method as below*

  • IntentCreate and navigate between two or more layout.You need two java codes and two layout xml.Create a new project called Hello Intent.Copy and paste java and xml into their directory and rename to SecondActivity.java and second_activity.xml

    *

  • IntentDesign both layouts Open AndroidManifest.xml and add the following codes to the xmlSecondActivity refering to SecondActivity.java

    *

  • IntentAdd onClick method for both buttons (OpenIntent2 for MainActivity.java) and (OpenIntent1 for SecondActivity.java)Add the following method to MainActivity.java

    Add the following method to SecondActivity.java

    Make sure both java file contain onCreate method that calling the correct xml layout file.

    *

  • Passing Data between layoutModify your Hello Intent project and by inserting in your OpenIntent2 method in MainActivity.java

    Add two textview in the second_activity.xml layout.*

  • Passing Data Between LayoutAdd the following code in onCreate method in SecondActivity.java

    *

  • Call Build in ApplicationBrowserCreate a new projectAdd a EditView and a button to the layoutAdd onClick methodCreate a CallBrowser method in MainActivity.java

    Add the following code to AndroidManifest.xml

    *

  • CallAdd one button to the existing projectInsert onClick option to the buttonAdd the following callPhone method to MainActivity.java

    Insert the following permission into AndroidManifest.xml*

  • CallTo enable call direct add the following method to a new button (dont forget to add onClick listener in xml layout.*

  • GPSCalling Google Maps*

  • SMSSending sms methodUsing the same project add a new button.Add the onClick listener to the buttonAdd the following method

    *

  • Read & Write DataRead and Write data to a text fileMethod to store data to a textfile*

  • Read & Write DataMethod to retrieve data

    Dont forget to import required method and also set the onClick listener*

  • A math gameCreate a new project and design your layout as Define the following var

    Add the following code to onCreate method*

  • A math gameAdd the following handleCheck method*

  • A math gameAdd the following handleNext method*

  • A math gameTipsTry to use the properties for each object to modify the design.Nested layout for buttonImport all required class *

  • Video and AudioPlay audio

    Add new folder inside your resource folder (R.raw) . Then add any audio file to the folder by dragging. (oppa is the name for this example)

    *

  • Video and AudioPlay Video*

  • NotificationCreate a new project and add a button and onClick listener*

  • Simple Animationhttp://mycodeandlife.wordpress.com/2012/07/07/android-simple-animation/*

  • Publishing Android App

  • Publishing Android App

  • Publishing Android App

  • Publishing Android App

  • General Publication StepsExport your application as an APK (Android Package) file.Generate your own self-signed certificate and digitally sign your application with it.Deploy the signed application.Use the Android Market for hosting and selling your application.

  • VersioningBeginning with version 1.0 of the Android SDKthe AndroidManifest.xml file includess:android:versionCode and android:versionName

  • Other AndroidManifest elementandroid:icon (within the element)android:label (within the element)

  • Digital SigningAll Android applications must be digitally signed before they are allowed to be deployedYou need not purchase digital certificates from a certificate authority (CA)You can generate your own self-signed certificate & use it to sign your Android applications.Eclipse uses a default debug keystore to sign your application. A keystore is commonly known as a digital certificate.

  • Specific StepsSelect your project in Eclipse and then select File Export.In the Export dialog, expand the Android item and select Export Android Application.Click Next.

  • Specific StepsSelect your project & Click Next.

  • Specific StepsSelect the Create new keystore option to create a new certificate (keystore) for signing your application.Enter a path to save your new keystore.Enter a password to protect the keystore. (For this example, type in password as the password). Click Next.

  • Specific StepsProvide an alias for the private key.Enter a password to protect the private key. (enter password)Enter a validity period for the key. Enter 50.According to Google, your application must be signed with a cryptographic private key whose validity period ends after 22 October 2033. Click Next.

  • Specific StepsEnter a path to store the destination APK file. Click Finish. APK file will now be generated.

  • Deploying APK FilesDeploying manually using the adb.exe toolHosting the application on a web serverPublishing through the Android MarketBesides the above methods, you can install your applications on users devices through e-mails, SD card, etc. As long as you can transfer the APK file onto the users device, you can install the application.

  • Publishing on the Google PlayCreate a developer profile at http://market.android.com/publish/Home. For this, you need a Google account (such as your Gmail account). Once you have logged in to the Android Market, you first create your developer profile.Click Continue (after entering the required information).

  • Publishing on the Google Play

  • Publishing on the Google PlayFor publishing on the Android Market, you need to pay a one-time registration fee, currently U.S.$25.Click the Google Checkout button to be redirected to a page where you can pay the registration fee. After paying, click the Continue link.

  • Publishing on the Google Play

  • Uploading Your APK FilesYou will be asked to supply some details for your application: The application in APK formatAt least two screenshots. A high-resolution application icon. This size of this image must be 512512 pixels.

    ****Open Handset Alliance, a consortium of 47hardware,software, andtelecomcompanies devoted to advancingopen standardsfor mobile devices. IncludesTexas Instruments,Broadcom Corporation,Google,HTC,Intel,LG,Marvell Technology Group,Motorola,Nvidia,Qualcomm,Samsung Electronics,Sprint NextelandT-Mobile**The linux kernel 2.6 is the hardware abstraction layer (HAL) between the hardware and the android software stack.*Maybe more profitable with ads than actually selling the app****26-28/2/2013CoPED UUM CAS (04-928477-)ANDROID PROGRAMMING WORKSHOP