Getting started with android dev and test perspective


Published on

The presentation covers basic intro to Android, how to get started with development, including instructions on setup, common UI usages like menus, dialogs; details on services like Sensors, Location and Google Maps
It also covers ideas on how to test including details on shell and installation instructions without using Eclipse

Published in: Education, Technology
1 Comment
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Getting started with android dev and test perspective

  1. 1. Getting started with Gunjan Kumar
  2. 2. Agenda <ul><li>Overview of Android </li></ul><ul><ul><li>Features and Architecture </li></ul></ul><ul><li>Setup for development (SDK, ADT) </li></ul><ul><li>Android Virtual Device </li></ul><ul><ul><li>Installing, using and installing applications </li></ul></ul><ul><li>Developing Android applications </li></ul><ul><li>Install / test on AVD </li></ul><ul><li>Ideas for testing </li></ul>
  4. 4. Overview <ul><li>Android is a software stack for mobile devices that includes an operating system, middleware and key applications </li></ul><ul><li>Based on the Linux kernel </li></ul><ul><li>Open Handset Alliance collaborated on Android's development and release </li></ul><ul><li>More than 33% of market share today. </li></ul><ul><li>3.1 Honeycomb for Tablet and 2.3.4 Gingerbread for Phones </li></ul><ul><li>App market with 200000+ apps, >3 billion downloads </li></ul>
  5. 5. History <ul><li>Android Inc founded in 2003 by Andy Rubin and other members. </li></ul><ul><li>Google acquired Android in August 2005. </li></ul><ul><li>Open Handset Alliance formed on 5 November 2007 to develop open standards for mobile devices. </li></ul><ul><li>Android unveiled as OHA’s first product. </li></ul><ul><li>Updates launched to fix bugs / add new features </li></ul><ul><li>The code names are in alphabetical order (Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, and the upcoming Ice Cream Sandwich). </li></ul>
  6. 6. Version history Version Name Release Date Beta 5 November 2007 1.0 23 September 2008 Android Market, Google account integration, maps … 1.1 9 February 2009 resolved issues, API changes … 1.5 Cupcake 30 April 2009 Widgets, upload to YouTube and Picasa … 1.6 Donut 15 September 2009 WVGA / CDMA support, Google navigation, Search enhancement … 2.0/2.1 Éclair 26 October 2009 / 12 January 2010 Live wallpaper, multiple screen resolutions, Camera flash … 2.2 Froyo 20 May 2010 Chrome’s V8 JavaScript engine, upload file in browser … 2.3 Gingerbread 6 December 2010 Voice and Video support in Gtalk … 3.0 / 3.1 Honeycomb 22 February 2011 / 10 May 2011 Released for tablets Ice Cream Sandwich Q4 2011 combination of Gingerbread and Honeycomb into a &quot;cohesive whole&quot;
  7. 7. Usage share / Market Share Source Year Symbian Android RIM iOS Microsoft Other OSs Gartner 2011 Q1 27.4% 36.0% 12.9% 16.8% 3.6% 3.3% Gartner 2010 37.6% 22.7% 16.0% 15.7% 4.2% 3.8% Gartner 2009 46.9% 3.9% 19.9% 14.4% 8.7% 6.1% Gartner 2008 52.4% 0.5% 16.6% 8.2% 11.8% 10.5% Gartner 2007 63.5% N/A 9.6% 2.7% 12.0% 12.1%
  8. 8. Features <ul><li>Application framework enabling reuse and replacement of components </li></ul><ul><li>Dalvik virtual machine optimized for mobile devices </li></ul><ul><li>Integrated browser based on the open source WebKit engine </li></ul><ul><li>Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional) </li></ul><ul><li>SQLite for structured data storage </li></ul><ul><li>Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF) </li></ul><ul><li>GSM Telephony (hardware dependent) </li></ul><ul><li>Bluetooth, EDGE, 3G, and WiFi (hardware dependent) </li></ul><ul><li>Camera, GPS, compass, and accelerometer (hardware dependent) </li></ul><ul><li>Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE </li></ul>
  9. 9. Android architecture
  11. 11. App development overview <ul><li>An open development platform, Android offers developers the ability to build extremely rich and innovative applications </li></ul><ul><li>Underlying all applications is a set of services and systems, including: </li></ul><ul><ul><li>A rich and extensible set of Views that can be used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser </li></ul></ul><ul><ul><li>Content Providers that enable applications to access data from other applications (such as Contacts), or to share their own data </li></ul></ul><ul><ul><li>A Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files </li></ul></ul><ul><ul><li>A Notification Manager that enables all applications to display custom alerts in the status bar </li></ul></ul><ul><ul><li>An Activity Manager that manages the lifecycle of applications and provides a common navigation backstack </li></ul></ul>
  12. 12. App development : options <ul><li> </li></ul><ul><li>SDK provided so you can use command line or IDE for app development </li></ul><ul><li>Eclipse based development for more elaborate development </li></ul><ul><ul><li>SDK + ADT (Android Developer Tool) </li></ul></ul><ul><ul><li>Set up Android Virtual Devices or hardware devices. </li></ul></ul><ul><ul><li>Create an Android project. </li></ul></ul><ul><ul><li>Build and run your application. </li></ul></ul><ul><ul><li>Debug your application with the SDK debugging and logging tools. </li></ul></ul><ul><ul><li>Test your application with the Testing and Instrumentation framework . </li></ul></ul>
  13. 13. Step 1 : Install SDK <ul><li>System requirement : </li></ul><ul><ul><li>So ensure you have JDK installed before you move to SDK installation </li></ul></ul><ul><li>Download from </li></ul><ul><li>Launch SDK Manager from the downloaded file to install platforms </li></ul>
  14. 14. Step 1 : Install SDK- tips <ul><li>Ensure that JDK is installed. </li></ul><ul><ul><li> </li></ul></ul><ul><li>Once JDK is installed, you can either use Installer or download ZIP for Android SDK </li></ul><ul><ul><li> </li></ul></ul><ul><li>Once SDK is installed, you will see a SDK Manager executable in the folder. </li></ul><ul><ul><li>Launch this to download platforms that will get added to the platforms folder </li></ul></ul><ul><ul><li>In office, you may have issues downloading from https so in the SDK manager, goto settings and check on the “ force HTTPS to be fetched as HTTP ” checkbox </li></ul></ul><ul><ul><li>If that doesn’t work out as well, try setting a proxy (say port 8888 ) </li></ul></ul><ul><li>Alternatively, you can copy this folder from any existing installation </li></ul>
  15. 15. Step 2 : Eclipse plug-in – Why? <ul><li>ADT (Android Developer Tool) plug-in for Eclipse simplifies development in Eclipse by providing </li></ul><ul><ul><li>Android Project Wizard helps create new project </li></ul></ul><ul><ul><li>Forms-based manifest, layout and resource editor </li></ul></ul><ul><ul><li>Building, conversion to .DEX (Android Executable), package to .APK and install to Dalvik VM is automated </li></ul></ul><ul><ul><li>AVD manager integrated with Eclipse for easy access to AVDs </li></ul></ul><ul><ul><li>DDMS (Dalvik Debug Monitoring Services) assists in monitoring </li></ul></ul><ul><ul><li>Debugging, breakpoints </li></ul></ul><ul><ul><li>Log and console outputs </li></ul></ul>
  16. 16. Step 2 : Eclipse plug-in : How? <ul><li>Help  Install new software </li></ul><ul><li>Add the following URL </li></ul><ul><ul><li> </li></ul></ul><ul><li>Select all from the Developer Tools </li></ul><ul><li>Restart and update ADT Preference </li></ul><ul><ul><li>Window  Preference </li></ul></ul><ul><ul><li>Mention the SDK Location </li></ul></ul>
  18. 18. Development in Eclipse
  19. 19. Create AVD and launch Emulator (command line) <ul><li>Android Virtual Device (AVD) is an emulator configuration that lets you model an actual device by defining hardware and software options to be emulated by the Android Emulator. </li></ul><ul><ul><li>See list of targets : android list targets </li></ul></ul><ul><ul><li>id: 2 or &quot;android-4&quot;      Name: Android 1.6      Type: Platform      API level: 4      Revision: 3      Skins: QVGA, HVGA (default), WVGA800, WVGA854 </li></ul></ul><ul><ul><li>Create AVD : android create avd -n my_avd -t 2 </li></ul></ul><ul><li>Run Emulator : emulator -avd <avd_name> </li></ul>
  20. 20. Create AVD from SDK Manager
  21. 21. Create AVD from Eclipse
  22. 22. Specifying details for AVD SD Card must be at least 9MB or left blank Skin allows to choose resolution / form factor for the device you want to emulate Name the device and select the target (the version of Platform that you want to emulate. Note that the list will be pulled out from the list of platforms you have installed on your machine (you can see in <sdk> platforms folder)
  23. 23. Emulator
  25. 25. Activities <ul><li>Presentation layer </li></ul><ul><li>Activity is a screen – only one gets user inputs at a time </li></ul><ul><li>An application can have more than one activities, each being a screen that the app can show to the user </li></ul><ul><li>Each activity extends </li></ul><ul><li>onCreate method is overridden to create or set the view – the actual layout of controls on the screen </li></ul>
  26. 26. Services <ul><li>Run in background, with no visible UI </li></ul><ul><li>Extend Service class </li></ul><ul><li>Typically used to develop services that need to be running even if the screen is closed </li></ul>
  27. 27. Intent <ul><li>Message passing mechanism within and between applications </li></ul><ul><li>Used for </li></ul><ul><ul><li>Starting a service or activity </li></ul></ul><ul><ul><li>Broadcast that an event has occurred – Android broadcasts intents for system events like “incoming phone call” </li></ul></ul><ul><ul><li>Declare your intent that an activity be started to perform an action with some data </li></ul></ul>Intent browserIntent = new Intent(Intent. ACTION_VIEW, Uri.parse(URL)); startActivity(browserIntent); Intent callIntent = new Intent(Intent. ACTION_CALL); callIntent.setData(Uri. parse(&quot;tel:&quot; + PhoneNumber)); startActivity(callIntent); void OpenHome(){ Intent myIntent = new Intent(QwestAvailabilityDetails.this, QwestHome.class); startActivity(myIntent); }
  28. 28. Content Provider <ul><li>Shareable data sources </li></ul><ul><li>Native content stores exposed by Android – media store, contacts, call logs etc. </li></ul>
  29. 29. Create new app Specify the project name as it should appear in your workspace Specify the target platform – depending on the device you are expecting this to run on Application Name – as will appear on the device Create Activity – the first activity that will be launched when app starts
  30. 30. What is generated? Named as the Create Activity specified when creating the app, this extends and serves as the “screen” that is shown to the user Auto generated file. DON’T MANIPULATE. Contains reference to all resources. Used in activities to access the resources Contains resources – layouts, images, values to be used in app – referenced via R Contains the icon which will be used on device for your app. Any more images that you use in the app must be added here. Add versions based on resolution to each of the folders Layouts specify the screens look and feel – think of it as HTML. Typically, you will have one layout for each activity. Main.xml is generated by default to correspond to the initial activity created by default Gives details like package, activity to be launched when app starts, permissions and intents – app configuration file of sorts Contains values specified as type, name and value. Can be of types other than string (say colors) Gives flexibility of configuring based on environment – one set for each environment Contains all the source code
  31. 31. AndroidManifest.xml <ul><li>Information for android to run your application like </li></ul><ul><ul><li>Package name / application name </li></ul></ul><ul><li><manifest package= &quot;“ android:versionCode= &quot;1“ android:versionName= &quot;1.0&quot;> </li></ul><ul><ul><li>List of all components – activities, services etc. </li></ul></ul><ul><ul><ul><li><activity android:name= &quot;.DemoViews&quot; android:label=&quot;@string/app_name&quot;> </li></ul></ul></ul><ul><ul><li>Identifies the activity which will be launched on app start </li></ul></ul><ul><li><activity android:name= &quot;.QwestHome&quot; android:label=&quot;@string/app_name&quot;> </li></ul><ul><ul><ul><li><intent-filter> </li></ul></ul></ul><ul><ul><ul><li><action android:name= &quot;android.intent.action.MAIN&quot; /> </li></ul></ul></ul><ul><ul><ul><li><category android:name= &quot;android.intent.category.LAUNCHER&quot; /> </li></ul></ul></ul><ul><ul><ul><li></intent-filter> </li></ul></ul></ul><ul><ul><ul><li></activity> </li></ul></ul></ul><ul><ul><li>Permissions to access protected parts of the API and interact with other applications </li></ul></ul><ul><ul><ul><li><uses-permission android:name= &quot;android.permission.INTERNET&quot; /> </li></ul></ul></ul><ul><ul><li>lists the libraries that the application must be linked against </li></ul></ul><ul><ul><ul><li><uses-library android:name= &quot;; /> </li></ul></ul></ul>
  32. 32. UI concepts : View <ul><li>View – basic unit of UI expression </li></ul><ul><ul><li>Can be specified as XML in res/layout folder and then inflated in the activity </li></ul></ul><ul><ul><li>setContentView(R.layout.alert); </li></ul></ul><ul><ul><li>Can be dynamically created and added to activity – partly (from another layout) or fully (creating and adding controls) </li></ul></ul><ul><ul><li>//We set a view to be shown on the page – this serves as outer shell </li></ul></ul><ul><ul><li>setContentView(R.layout.materpage); </li></ul></ul><ul><ul><li>//To this shell, we inflate another view which is present in another XML </li></ul></ul><ul><ul><li>TableLayout tlContainer = (TableLayout) findViewById(; </li></ul></ul><ul><ul><li>LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); </li></ul></ul><ul><ul><li>View itemView = inflater.inflate(R.layout.viewbill, null); </li></ul></ul><ul><ul><li>tlContainer.addView(itemView, new TableLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); </li></ul></ul>
  33. 33. UI Concepts : View <ul><li>Dynamically creating views and adding to layout </li></ul>View mainPanel = CreateView(); setContentView(R.layout. materpage); TableLayout tlContainer = (TableLayout) findViewById( containerForIndividualLayout); tlContainer.addView(mainPanel); private ViewGroup CreateView() { LinearLayout panel = new LinearLayout(this); panel.setLayoutParams(new LayoutParams(LayoutParams. FILL_PARENT, LayoutParams.FILL_PARENT)); panel.setOrientation(LinearLayout. VERTICAL); panel.setPadding(10, 0,0,0); panel.setBackgroundColor(Color. TRANSPARENT); TextView txtHeader = new TextView(getApplicationContext()); txtHeader.setText(&quot;Congratulations! You qualify for the following products.&quot;); txtHeader.setTextSize(20);
  34. 34. UI Concepts : Layout <ul><li>Layout – type of layout architectures telling how the children are aligned </li></ul><ul><ul><li>LinearLayout : aligns all children in a single direction — vertically or horizontally </li></ul></ul><ul><ul><li>RelativeLayout : child views specify their position relative to the parent view or to each other </li></ul></ul><ul><ul><li>TableLayout : positions its children into rows and columns </li></ul></ul><ul><ul><li>FrameLayout : Blank space where children are pinned to top left corner </li></ul></ul><ul><ul><li> </li></ul></ul>
  35. 35. UI Concepts: Widgets and events <ul><li>Inherit from android.widget </li></ul><ul><li>Serves as an interface for interaction with the user </li></ul><ul><li>Buttons, text views (editable / read only), date picker etc. </li></ul><ul><li>Once View / Widgets defined, you want to know of user interactions – do use events </li></ul><ul><ul><li>Define an event listener and register it with the View </li></ul></ul><ul><ul><li>btnAlert.setOnClickListener(this); </li></ul></ul><ul><ul><li>OR </li></ul></ul><ul><li>alertDialog.setButton(&quot;Btn1&quot;, new DialogInterface.OnClickListener() { </li></ul><ul><li> public void onClick(DialogInterface dialog, int which) { </li></ul><ul><li> showToast(message + &quot;. You pressed Btn1 : &quot; + which, getApplicationContext()); </li></ul><ul><ul><li>View class gives multiple callback methods by default </li></ul></ul><ul><ul><ul><li>onClick / onLongClick / onFocusChange / onTouch etc. </li></ul></ul></ul>
  36. 36. UI Concepts: Options Menu <ul><li>This is shown when Menu button of phone is pressed </li></ul><ul><li>Create a view under res/menu/ for look and feel </li></ul><ul><li>Define appearance for the menu (onCreateOptionsMenu) either from view OR dynamically </li></ul><ul><li>Respond to user selection (onOptionsItemSelected) </li></ul><ul><li>For submenu, add menu as child to item in the view. </li></ul>
  37. 37. UI Concepts: Options Menu @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate( main_menu, menu); return true; } <ul><li>@Override </li></ul><ul><li>public boolean onOptionsItemSelected(MenuItem item) { </li></ul><ul><ul><li>// Handle item selection </li></ul></ul><ul><ul><li>switch (item.getItemId()) </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><ul><li>case menu_item_alerts: </li></ul></ul></ul><ul><ul><ul><li>//todo </li></ul></ul></ul><ul><ul><ul><li>return true; </li></ul></ul></ul><ul><ul><ul><li>case menu_item_views: </li></ul></ul></ul><ul><ul><ul><li>//todo </li></ul></ul></ul><ul><ul><ul><li>return true; </li></ul></ul></ul><ul><ul><ul><li>default: </li></ul></ul></ul><ul><ul><ul><li>return super.onOptionsItemSelected(item); </li></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>resource main_menu is defined with items like : <item android:id= &quot;@+id/menu_item_alerts&quot; android:icon= &quot;@drawable/icon_menu_alert&quot; android:title= &quot;Alerts Demo&quot; />
  38. 38. UI Concepts: Context Menu <ul><li>This is shown when a control is pressed for long </li></ul><ul><li>Similar to the “right click” on PC </li></ul><ul><li>Create it for any view </li></ul><ul><li>Create a view under res/menu/ for look and feel </li></ul><ul><li>Register that view for a context menu (registerForContextMenu) </li></ul><ul><li>Define appearance for the menu (onCreateContextMenu) either from view OR dynamically </li></ul><ul><li>Respond to user selection (onContextItemSelected) </li></ul>
  39. 39. UI Concepts: Context Menu @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getMenuInflater(); inflater.inflate( context_menu, menu); } @Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case ctx_menu_item_option_1: showToast(&quot;context menu option 1 selected&quot;, getApplicationContext()); return true; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState setContentView(R.layout.alert); txtAlertName = (EditText)findViewById(; registerForContextMenu(txtAlertName);
  40. 40. UI Concepts: Alerts / Dialogs Toast AlertDialog ProgressDialog DatePickerDialog TimePickerDialog
  41. 41. UI Concepts: Alerts / Dialogs int duration = Toast. LENGTH_SHORT; Toast toast = Toast. makeText(appContext, message, duration);; TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { //TODO : When user selects time }}; TimePickerDialog timePicker = new TimePickerDialog(this, mTimeSetListener, mHour, mMinute, true);; DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { //TODO : when user selects Date }}; DatePickerDialog datePicker = new DatePickerDialog(this, mDateSetListener, cyear, cmonth, cday);; Toast DatePickerDialog TimePickerDialog
  42. 42. UI Concepts: Alerts / Dialogs ProgressDialog dialog = new ProgressDialog( DemoAlerts.this); dialog.setMessage(&quot;This is the content you want to show - like please wait while we fetch your account details...&quot;); dialog.setProgressStyle(ProgressDialog. STYLE_SPINNER); // dialog.setProgressStyle(ProgressDialog. STYLE_HORIZONTAL);// this gives progress bar; AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle(&quot;This is the title for the window&quot;); alertDialog.setMessage(&quot;The dialog message goes here. This can be any text and as per the length, it will wrap this.&quot;); alertDialog.setButton(&quot;Btn1&quot;, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {//TODO on button click } }); alertDialog.setButton2(&quot;Btn2&quot;, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {//TODO on button click } }); alertDialog.setButton3(&quot;Btn3&quot;, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {//TODO on button click } }); alertDialog.setIcon(R.drawable. icon);; ProgressDialog AlertDialog
  43. 43. UI Concepts: Status Bar Notification <ul><li>Primarily for services to notify the user </li></ul><ul><li>Get a reference to the NotificationManager </li></ul><ul><li>Instantiate the Notification </li></ul><ul><li>Define the Notification's expanded message and Intent </li></ul><ul><li>Pass the Notification to the NotificationManager </li></ul>
  44. 44. SESSION 2 : Agenda <ul><li>Quick recap of last session and any open questions </li></ul><ul><li>Sensors </li></ul><ul><li>Location based services </li></ul><ul><li>Geocoding / reverse geocoding </li></ul><ul><li>Maps </li></ul><ul><li>Console </li></ul><ul><li>Testing ideas </li></ul>
  45. 45. Sensors <ul><li>SensorManager lets you access device sensors </li></ul><ul><li>Like other system services, you need to get a reference to it </li></ul><ul><ul><li>getSystemService( SENSOR_SERVICE) </li></ul></ul><ul><li>Determine the sensor you want to listen to (accelerometer, orientation, temperature etc.) </li></ul><ul><ul><li>private static final int sensorToListenFor = SensorManager.SENSOR_ORIENTATION; </li></ul></ul><ul><li>Since services work in a publish-subscribe mode, implement a listener and override the onSensorChanged </li></ul><ul><ul><li>One of the values you get is “ float[] values ” and this will contain values depending on the type of sensor you are listening to </li></ul></ul><ul><ul><li> </li></ul></ul><ul><li>Since sensors involve lot of processing to get the data, register and unregister to save battery and processing power </li></ul>
  46. 46. Sensors Example - orientation <ul><li>Get an instance by calling Context.getSystemService </li></ul><ul><ul><li>sensorManager = (SensorManager)getSystemService( SENSOR_SERVICE); </li></ul></ul><ul><li>Determine the sensors you want to get data from </li></ul><ul><ul><li>private static final int sensorToListenFor = SensorManager.SENSOR_ORIENTATION; </li></ul></ul><ul><li>Implement a listener and override onSensorChanged </li></ul><ul><li>Register and unregister listener to this in the resume and pause </li></ul> @Override public void onResume() / onPause() { super.onResume(); sensorManager.registerListener / unregisterListener (this, sensorToListenFor); } public void onSensorChanged(int sensor, float[] values) { if(sensor == sensorToListenFor) { float azimuth = Math. round(values[0]); float pitch = Math. round(values[1]); float roll = Math. round(values[2]);
  47. 47. Sensors Example - orientation values[0]: Azimuth, angle between the magnetic north direction and the y-axis, around the z-axis (0 to 359). 0=North, 90=East, 180=South, 270=West values[1]: Pitch, rotation around x-axis (-180 to 180), with positive values when the z-axis moves toward the y-axis. values[2]: Roll, rotation around y-axis (-90 to 90), with positive values when the x-axis moves toward the z-axis.
  48. 48. Sensors - testing <ul><li>Almost all sensors require a physical device to test </li></ul><ul><li>Emulator OR console DO NOT offer commands to simulate sensor values </li></ul><ul><li>Few open source options like which can simulate sensors </li></ul>
  49. 49. Sensor testing : snapshots from phone Azimuth around 0 – phone is pointing in the North direction Azimuth around 90 – phone is pointing in the East direction Azimuth around 180 – phone is pointing in the South direction Azimuth around 270 – phone is pointing in the West direction Pitch around 0 – phone is “lying flat” Pitch around -90 – phone is “standing” Pitch around 90 – phone is “standing on its head” Roll around 0 – phone is “lying flat” Roll around -90 – phone is “standing on its side”
  50. 50. Location Based Services <ul><li>Location services of the device are accessible through android.location </li></ul><ul><li>LocationManager is a system service that provides APIs for access to device location </li></ul><ul><li>There are multiple location providers (GPS, Network etc.) and we need to select the provider to use </li></ul><ul><li>Request an instance of LocationManager </li></ul><ul><ul><li>lm = (LocationManager)getSystemService(Context. LOCATION_SERVICE) </li></ul></ul><ul><li>Get last known location </li></ul><ul><ul><li>Location lastKnown = lm.getLastKnownLocation(LocationManager. GPS_PROVIDER) </li></ul></ul><ul><li>Add a hook to listen to location updates (implement LocationListener) </li></ul><ul><ul><li>lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener) </li></ul></ul><ul><li>Request permission in Manifest </li></ul><ul><li><uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /> </li></ul>
  51. 51. Location Listener and Manager <ul><li>requestLocationUpdates </li></ul><ul><ul><li>provider: The name of the provider with which you register </li></ul></ul><ul><ul><li>minTime: The minimum time interval for notifications, in milliseconds. </li></ul></ul><ul><ul><li>minDistance: The minimum distance interval for notifications, in meters. </li></ul></ul><ul><ul><li>listener: An object whose onLocationChanged() method will be called for each location update. </li></ul></ul><ul><li>LocationListener </li></ul><ul><ul><li>onLocationChanged(Location location): This method is called when the location has changed. </li></ul></ul><ul><ul><li>onProviderDisabled(String provider): This method is called when the provider is disabled by the user. </li></ul></ul><ul><ul><li>onProviderEnabled(String provider): This method is called when the provider is enabled by the user. </li></ul></ul><ul><ul><li>onStatusChanged(String provider, int status, Bundle extras): This method is called when the provider status changes </li></ul></ul><ul><li>Location </li></ul><ul><ul><li>.getLatitude() and .getLongitude() used to get latitude and longitude </li></ul></ul>
  52. 52. Location : Testing <ul><li>Location can be sent as individual co-ordinate OR KML (refer to ) </li></ul><ul><li>You can also use console are given in next slide </li></ul><ul><li>To get a KML for a route, you can use a URL like below to get the path in KML format </li></ul><ul><ul><li>,77.704747&daddr=12.93625,77.690073&ie=UTF8&0&om=0&output=kml </li></ul></ul>
  53. 53. Location : Testing : Sending location from console <ul><li>Open console : telnet localhost <emulator number> </li></ul><ul><ul><li>telnet localhost 5554 </li></ul></ul><ul><li>Background : geocoding allows you to get geo location from an address </li></ul><ul><ul><li>If you try a URL like :,+Denver,+CO&sensor=true </li></ul></ul><ul><ul><li><geometry><location><lat>39.7442190</lat><lng>-104.9894830</lng></location> </li></ul></ul><ul><li>In applications that use device’s current location </li></ul><ul><ul><li>we can test by sending different locations from console </li></ul></ul>
  54. 54. Geocoding <ul><li>Geocoding is the process of relating location and other geographic data like address, zip code etc </li></ul><ul><li>Forward geocoding </li></ul><ul><ul><li>also referred to as simply Geocoding </li></ul></ul><ul><ul><li>Process of getting location from geographic data </li></ul></ul><ul><ul><li>Using Google Map API WS, you can just enter a URL like below to get an XML (you can also get JSON by using geocode/JSON? instead of geocode/xml?,+Denver,+CO&sensor=true </li></ul></ul><ul><li>Reverse geocoding </li></ul><ul><ul><li>Process of getting geographic data like Address / Postal Code from location </li></ul></ul><ul><ul><li>Using Google Map API WS, you can use a URL like below to get the address in XML / JSON format. Note that this can be approximate match PLUS can return more than one address </li></ul></ul><ul><ul><li>,-73.961452&sensor= true_or_false </li></ul></ul>
  55. 55. Geocoding support in Android <ul><li>Geocoder has methods getFromLocation and getFromLocationName for forward and reverse geocode </li></ul><ul><ul><li>Geocoder geoCoder = new Geocoder(appContext , Locale. getDefault()); </li></ul></ul>try { List<Address> addresses = geocoder.getFromLocation(location.getLatitude(),location.getLongitude(), 10); for(Address currentAddress : addresses) { lblShowLocation.append(&quot;n&quot; + currentAddress.getAddressLine(0)); } } catch (IOException e) {e.printStackTrace(); } try { List<Address> locations= geocoder.getFromLocationName(“1600 Glenarm Place, Denver, CO”, 10); for(Address currentLocation: locations) { lblShowLocation.append(&quot;n&quot; + currentLocation .getLatitude()); } } catch (IOException e) {e.printStackTrace(); }
  56. 56. Maps <ul><li>Google Maps is an external library </li></ul><ul><li>Download the api (Requires Android SDK 1.5 or above) </li></ul><ul><ul><li> </li></ul></ul><ul><li>Register api key </li></ul><ul><ul><li> </li></ul></ul><ul><li>MapView is the Map View control </li></ul><ul><li>MapActivity is the base class you extend in your activity </li></ul><ul><li>Overlay is used to annotate your maps </li></ul><ul><ul><li>You can use a canvas to draw </li></ul></ul><ul><li>MapController used to center location, zoom etc. </li></ul><ul><li>ItemizedOverlays and OverlayItems used to create layer of map markers </li></ul>
  57. 57. Maps : register API key <ul><li>Run the following to get your MD5 cert </li></ul><ul><ul><li>keytool -list -alias androiddebugkey -keystore <path_to_debug_keystore>.keystore -storepass android -keypass android </li></ul></ul><ul><li>Goto : </li></ul><ul><ul><li>Enter the MD5 signature </li></ul></ul><ul><ul><li>Use the key in MapView </li></ul></ul>C:>keytool -list -alias androiddebugkey -keystore &quot;C:Documents and Settingsgxkumar.androiddebug.keystore&quot; -storepass android -keypass android androiddebugkey, Jun 22, 2011, PrivateKeyEntry, Certificate fingerprint (MD5): 32:E4:29:6C:2B:98:9C:33:41:5F:7F:43:CA:04:C7:33
  58. 58. Maps : how to show map? <ul><li>Create activity that extends MapActivity </li></ul><ul><ul><li>isRouteDisplayed needs to be overridden mandatorily </li></ul></ul><ul><li>Add MapView to your layout along with the apiKey </li></ul><ul><ul><li>< … android:apiKey= “Maps_ApiKey_String“/> </li></ul></ul><ul><li>Add uses-library to manifest </li></ul><ul><ul><li><uses-library android:name=&quot;; /> </li></ul></ul><ul><li>Add permission to manifest </li></ul><ul><ul><li><uses-permission android:name=&quot;android.permission.INTERNET&quot; /> </li></ul></ul><ul><li>When location changes, the map will NOT center to it by default. We need to handle that via MapController.setCenter(GeoPoint point) </li></ul>
  59. 59. Maps : respond to location update To add zoom controls: mapView = (MapView)findViewById( mapview); mapView.setBuiltInZoomControls(true); To show the location on map In the onCreate method : MapController mc = mapView.getController(); In listener : public void onLocationChanged(Location loc) { … … GeoPoint p = new GeoPoint( (int) (loc.getLatitude() * 1E6), (int) (loc.getLongitude() * 1E6)); mc.animateTo(p); mc.setZoom(13); To set view of map mapView.setSatellite(true); mapView.setStreetView(true);
  60. 60. Maps : overlays <ul><li>Overlays are layers added one over other on top of map </li></ul><ul><li>They are inherently transparent </li></ul><ul><li>Mostly used to add markers / draw on the map </li></ul><ul><ul><li>Overlay is providing a canvas to draw on </li></ul></ul><ul><li>Two options to ad overlays to map </li></ul><ul><ul><li>Implement a class that extends Overlay </li></ul></ul><ul><ul><ul><li>Override draw method to allow you to draw on the canvas </li></ul></ul></ul><ul><ul><ul><li>Use projections to translate geo points to canvas points </li></ul></ul></ul><ul><ul><ul><li>Override onTap to do some action when a geo point is tapped by the user </li></ul></ul></ul><ul><ul><li>Implement a class that extends ItemizedOverlay<OverlayItem> </li></ul></ul><ul><ul><ul><li>Each overlay item is defined by GeoPoint, Text and Snippet </li></ul></ul></ul><ul><ul><ul><li>Override draw to allow to draw on canvas – say connect locations </li></ul></ul></ul>
  61. 61. Maps : add marker Add Markers //get the overlays and clear it List<Overlay> mapOverlays = mapView.getOverlays(); mapOverlays.clear(); //first we need to define the drawable using one of the icons Drawable drawable = this.getResources().getDrawable(R.drawable. icon_map_marker); //initialize the itemized overlay using the current marker CustomItemizedOverlay mapOverlay = new CustomItemizedOverlay(drawable); GeoPoint point = new GeoPoint((int) (( loc.getLatitude()) * 1E6), (int) ((loc.getLongitude()) * 1E6)); OverlayItem overlayitem = new OverlayItem(point, &quot;title&quot;, &quot;snippet&quot;); mapOverlay.addOverlay(overlayitem); mapOverlays.add(mapOverlay); mapView.invalidate(); class CustomItemizedOverlay extends ItemizedOverlay
  62. 62. Maps : keep adding markers public void AddLocationToMap(Location loc) { //get the overlays and clear it List<Overlay> mapOverlays = mapView.getOverlays(); mapOverlays.clear(); GeoPoint point = new GeoPoint((int) (( loc.getLatitude()) * 1E6), (int) ((loc.getLongitude()) * 1E6)); String addressForPoint = &quot;&quot;; addressForPoint = GetAddressFromPoint(point, getApplicationContext()); lblAddress.setText(addressForPoint); //create an overlay items OverlayItem overlayitem = new OverlayItem(point, &quot;Address : &quot; + addressForPoint, &quot;snippet&quot;); //add it to the our customized overlay item list itemizedOverlay.addOverlay(overlayitem); //add the current list to mapOverlays mapOverlays.add(itemizedOverlay); //invalidate will force to redraw the map mapView.invalidate(); }
  63. 63. Caution while listening for location change <ul><li>This is the screen capture from my cell after 500m of walking. </li></ul><ul><li>Current setting was “locationManager.requestLocationUpdates(LocationManager. GPS_PROVIDER , 1000, 1” </li></ul><ul><li>Also keep in mind that the location fixed by GPS can keep varying so be sure you are not using less accurate points </li></ul><ul><li>Depending on your application’s need, alter the frequency of check and distance change when listener should report a change. </li></ul><ul><li>Remember – GPS will consume battery and data so use it wisely </li></ul>
  64. 64. Maps : sample app for tracking your path <ul><li>Few key things to note </li></ul><ul><li>Since the app used to un-register from Location Listening onPause, the area where cell phone screen was off – there were no locations captured </li></ul><ul><ul><li>So depending on your app, decide whether you want to listen always or not </li></ul></ul><ul><li>Frequency of listening is very critical </li></ul><ul><ul><li>Listen more frequently – and you end up showing lot of points </li></ul></ul><ul><ul><li>Listen less frequently and your path is not plotted correctly </li></ul></ul>
  66. 66. Installing and running the app <ul><li>The executable is a .APK file which can be installed on device or run on emulator </li></ul><ul><li>SDK includes a virtual mobile device emulator </li></ul><ul><li>Create AVD with required configuration and run on emulator </li></ul><ul><li>Controls in emulator for most functionality. </li></ul><ul><li>Each emulator instance provides a control console the you can connect to, to issue commands that are specific to that instance. </li></ul>
  67. 67. Install APK to AVD <ul><li>Ensure that AVD is created and emulator is running </li></ul><ul><li>Place .apk file in /tools folder on SDK </li></ul><ul><li>On the command prompt, goto android SDK /tools folder: </li></ul><ul><ul><li>adb install my_android_app.apk </li></ul></ul><ul><li>The apk file can be located anywhere – you just need the path when running this command </li></ul><ul><li>Once this is complete, you can see the app installed in your home / app </li></ul>
  68. 68. Console <ul><li>Each running emulator instance includes a console facility that lets you dynamically query and control the simulated device environment </li></ul><ul><ul><li>telnet localhost <console-port>. Console Port starts with 5554 </li></ul></ul><ul><ul><li>Once console is launched, you can use commands to send events, location change etc to the device </li></ul></ul>
  69. 69. Example : Sending geocode from console <ul><li>Background : geocoding allows you to get geo location from an address </li></ul><ul><ul><li>If you try a URL like :,+Denver,+CO&sensor=true </li></ul></ul><ul><ul><li><geometry><location><lat>39.7442190</lat><lng>-104.9894830</lng></location> </li></ul></ul><ul><li>In applications that use device’s current location, we can test by sending different locations from console </li></ul>
  70. 70. Available console commands
  72. 72. Mobile testing types <ul><li>Functional Testing : basic functionality of app is working </li></ul><ul><ul><li>Emulator testing will cover this </li></ul></ul><ul><li>Usability Testing : after stable basic app is ready </li></ul><ul><ul><li>Say scrolling to bottom of screen is not easy in non-touch devices </li></ul></ul><ul><li>Performance Testing : across devices, carriers, location </li></ul>
  73. 73. Mobile testing methods <ul><li>Emulator / Simulator </li></ul><ul><li>In House : setup lab </li></ul><ul><li>Out sourcing : </li></ul><ul><ul><li>Device ready : </li></ul></ul><ul><ul><li>Droid Cloud : </li></ul></ul><ul><ul><li>uTest : </li></ul></ul>
  74. 74. Ideas for Testing <ul><li>When launching emulator / creating AVD, we can select resolution – try to test on multiple resolutions / screen sizes </li></ul><ul><ul><li>android create avd -n <name> -t <targetID> --skin WVGA800 </li></ul></ul><ul><ul><li>If you were launching from Eclipse, you can select as shown </li></ul></ul><ul><ul><li>If you launch SDK Manager, you can add new AVD from there and select the resolution </li></ul></ul>
  75. 75. Ideas for testing <ul><li>Flow of application </li></ul><ul><ul><li>Screen transitions – upon clicks / slide if permitted </li></ul></ul><ul><ul><li>When doing processing, does it show a progress bar? </li></ul></ul><ul><ul><li>Is it responsive? </li></ul></ul><ul><ul><li>Simulate a call when app is running to see if it hangs </li></ul></ul>
  76. 76. Ideas for testing <ul><li>Orientation change </li></ul><ul><ul><li>To ensure that the app responds well in both orientation </li></ul></ul><ul><ul><li>CTRL+F11 / F12 </li></ul></ul>
  77. 77. References <ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> : Robotium is a test framework created to make it easy to write powerful and robust automatic black-box test cases for Android applications. With the support of Robotium, test case developers can write function, system and acceptance test scenarios, spanning multiple Android activities. </li></ul><ul><li> </li></ul>
  78. 78. Q and A ?
  79. 79. <ul><li>Thank You  </li></ul><ul><li>[email_address] </li></ul><ul><li>[email_address] </li></ul>