Programming Mobile Applications with Android



Similar documents
Sensors & Motion Sensors in Android platform. Minh H Dang CS286 Spring 2013

Android Sensors. CPRE 388 Fall 2015 Iowa State University

ELET4133: Embedded Systems. Topic 15 Sensors

Android Sensor Programming. Weihong Yu

Android Sensors. XI Jornadas SLCENT de Actualización Informática y Electrónica

Using Sensors on the Android Platform. Andreas Terzis Android N00b

Android Framework. How to use and extend it

getsharedpreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter.

06 Team Project: Android Development Crash Course; Project Introduction

Android app development course

! Sensors in Android devices. ! Motion sensors. ! Accelerometer. ! Gyroscope. ! Supports various sensor related tasks

Developing Sensor Applications on Intel Atom Processor-Based Android* Phones and Tablets

App Development for Smart Devices. Lec #4: Files, Saving State, and Preferences

Objective. Android Sensors. Sensor Manager Sensor Types Examples. Page 2

Android Concepts and Programming TUTORIAL 1

Android app development course

Android Development Tutorial. Nikhil Yadav CSE40816/ Pervasive Health Fall 2011

Using the Android Sensor API

Using Extensions or Cordova Plugins in your RhoMobile Application Darryn

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Android on Intel Course App Development - Advanced

Iotivity Programmer s Guide Soft Sensor Manager for Android

Android Persistency: Files

Android. Mobile Computing Design and Implementation. Application Components, Sensors. Peter Börjesson

ITG Software Engineering

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

CS 403X Mobile and Ubiquitous Computing Lecture 6: Maps, Sensors, Widget Catalog and Presentations Emmanuel Agu

Graduate presentation for CSCI By Janakiram Vantipalli ( Janakiram.vantipalli@colorado.edu )

Wiley Publishing, Inc.

Mobile Application Development Google Maps Android API v2

Introduction to Android. CSG250 Wireless Networks Fall, 2008

E0-245: ASP. Lecture 16+17: Physical Sensors. Dipanjan Gope

Android in Action. Second Edition. Revised Edition of Unlocking Android MANNING. (74 w. long.) W. FRANK ABLESON CHRIS KING ROBI SEN.

Getting Started with Android Programming (5 days) with Android 4.3 Jelly Bean

Module Title: Software Development A: Mobile Application Development

[PACKTl. Flash Development for Android Cookbook. Flash, Flex, and AIR. Joseph Labrecque. Over 90 recipes to build exciting Android applications with

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Designing An Android Sensor Subsystem Pitfalls and Considerations

Develop a Hello World project in Android Studio Capture, process, store, and display an image. Other sensors on Android phones

Android Application Development

Developer's Cookbook. Building Applications with. The Android. the Android SDK. A Addison-Wesley. James Steele Nelson To

Beginner s Android Development Tutorial!

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

Creating a 2D Game Engine for Android OS. Introduction

ANDROID INTRODUCTION TO ANDROID

TUTORIAL. BUILDING A SIMPLE MAPPING APPLICATION

Android Programming Lecture 18: Menus Sensors 11/11/2011

App Development for Smart Devices. Lec #5: Android Sensors

Obsoleted chapter from The Busy Coder's Guide to Advanced Android Development

Introduction to Android

Android Application Development

How to develop your own app

Mobile Apps with App Inventor

Android Basics. Xin Yang

Pedometer Project 1 Mr. Michaud /

Desi g n Document. Life Monitor. Group Members: Kenny Yee Xiangxiong Shi Emmanuel Panaligan

A Scalable Network Monitoring System as a Public Service on Cloud

Module 1: Sensor Data Acquisition and Processing in Android

AUTOMATIC HUMAN FREE FALL DETECTION USING ANDROID

ANDROID ALERT APP (SHOP SALE)

Google Android Syllabus

AdFalcon Android SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

Developing Applications for ios

Android (Basic + Advance) Application Development

Mocean Android SDK Developer Guide

How To Write A File Station In Android.Com (For Free) On A Microsoft Macbook Or Ipad (For A Limited Time) On An Ubuntu 8.1 (For Ubuntu) On Your Computer Or Ipa (For

CHAPTER 1: INTRODUCTION TO ANDROID, MOBILE DEVICES, AND THE MARKETPLACE

Mobile Application GPS-Based

CSE476 Mobile Application Development. Yard. Doç. Dr. Tacha Serif Department of Computer Engineering Yeditepe University

Android Application Development Distance Learning Program Brochure

COURSE CONTENT. GETTING STARTED Select Android Version Create RUN Configuration Create Your First Android Activity List of basic sample programs

How To Use Titanium Studio

Application Development

Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

ID TECH UniMag Android SDK User Manual

«compl*tc IDIOT'S GUIDE. Android App. Development. by Christopher Froehlich ALPHA. A member of Penguin Group (USA) Inc.

Android Fundamentals 1

Frameworks & Android. Programmeertechnieken, Tim Cocx

CS 528 Mobile and Ubiquitous Computing Lecture 2: Android Introduction and Setup. Emmanuel Agu

Designing for the Mobile Web Lesson 3: HTML5 Web Apps

Internal Services. CSE 5236: Mobile Application Development Instructor: Adam C. Champion Course Coordinator: Dr. Rajiv Ramnath

Transcription:

Programming Mobile Applications 22-26 September, Albacete, Spain Jesus Martínez-Gómez

Introduction to advanced android capabilities Maps and locations.- How to use them and limitations. Sensors.- Using sensors to obtain real-time data External Data.- How to access files, databases and content providers Android Lab V OSSCOM Programming Mobile Applications 2

In this lesson, we will learn: What advanced capabilities are included in Android and how to use them How to use localization and maps in our applications How to access data not stored in our applications OSSCOM Programming Mobile Applications 3

Introduction to advanced android capabilities We have seen how to develop Android applications similar to desktop ones Multimedia elements Graphical user interfaces Life Cycle Access to the camera but the execution in a mobile phone allows for new and more powerful functionalities OSSCOM Programming Mobile Applications 4

Introduction to advanced android capabilities Mobile phones are equipped with Cameras GPS Tactile screen Temperature and humidity sensors Accelerometer and compass Access to Google services Networking Mobile capabilities: contacts, calls, sms, etc OSSCOM Programming Mobile Applications 5

Introduction to advanced android capabilities Using some of these elements, we can: Develop an application that generates a map with the images acquired in a specific environment Create new gestures to speed-up repetitive actions, like the introduction of contacts in the agenda Create an application for notifying when the temperature arises a threshold Develop applications to acquired the quality of our domestic wireless network and then present some statistics... OSSCOM Programming Mobile Applications 6

Maps and locations.- How to use them and limitations. Localization services are basic for the development of useful applications Where can I find the nearest fuel station? Where can I find the place where I took a photograph Load advertisements only when the localization is the appropriate For instance, a Restaurant 2x1 ticket when the user is close to the closest Restaurant OSSCOM Programming Mobile Applications 7

Maps and locations. How to retrieve the current location? We will develop both a service and an activity Service to provide localization capabilities Activity to require access to the service Permissions <uses-permission android:name="android.permission.access_network_state"/> <uses-permission android:name="android.permission.change_network_state"/> <uses-permission android:name="android.permission.access_wifi_state"/> <uses-permission android:name="android.permission.change_wifi_state"/> <uses-permission android:name="android.permission.access_fine_location" /> OSSCOM Programming Mobile Applications 8

Maps and locations. How to retrieve the current location? - Service Class Implements LocationListener A set of methods should be implemented onlocationchanged(location location) Key variables Location mylocation Context mycontext GetLocation() method returns the location by using the locationmanager obtained from mycontext OSSCOM Programming Mobile Applications 9

Maps and locations.- How to use them and limitations. How to retrieve the current location? - Service Class locationmanager = (LocationManager) mycontext.getsystemservice(location_service); locationmanager.requestlocationupdates(locationmanager.gps_provider,6000,10, this); mylocation = locationmanager.getlastknownlocation(locationmanager.gps_provider); mylatitude = mylocation.getlatitude(); mylongitude= mylocation.getlongitude(); OSSCOM Programming Mobile Applications 10

Maps and locations.- How to use them and limitations. How to retrieve the current location? - Activity Includes an object of the service class that provides the localization We can now obtain out latitude and longitude when needed If the GPS is not enable, it will fail There should be checked that GPS is working or open the localization settings OSSCOM Programming Mobile Applications 11

Maps and locations.- How to use them and limitations. Once we can access to our location, the following step consist in using maps We can add maps based on Google Maps data The Google Maps API provides access to: Maps Servers Data Download Map Display Touch Gestures OSSCOM Programming Mobile Applications 12

Maps and locations. We will need to install the Google Play services SDK https://developer.android.com/google/play-services/setup.html First, copy the folder in our workspace android-sdks\extras\google\google_play_services\libproject Then, add this project as library Right button properties Android OSSCOM Programming Mobile Applications 13

Maps and locations. OSSCOM Programming Mobile Applications 14

Maps and locations. We need an Android Certificate and the Google Maps API key https://code.google.com/apis/console/?noredirect#project:1017833389 Services activate the Google Maps Android API v2 OSSCOM Programming Mobile Applications 15

Maps and locations. We need an Android Certificate and the Google Maps API key We need to use our SHA1 certificate fingerprint Windows -> Preferences -> Android -> Build And then use it to obtain the Key and modify the manifest file and include the following lines <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasyc9y40rcnx..." /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> OSSCOM Programming Mobile Applications 16

Maps and locations We now should have all these permissions <uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.write_external_storage"/> <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices"/> <uses-permission android:name="android.permission.access_network_state"/> <uses-permission android:name="android.permission.change_network_state"/> <uses-permission android:name="android.permission.access_wifi_state"/> <uses-permission android:name="android.permission.change_wifi_state"/> <uses-permission android:name="android.permission.access_fine_location" /> <uses-permission android:name="android.permission.access_coarse_location"/> OSSCOM Programming Mobile Applications 17

Maps and locations Now we can add and manage google maps in out applications Usefull webpage http://www.gps-coordinates.net/ We can obtain the coordinates of any worldwide location Layout <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.mapfragment" /> OSSCOM Programming Mobile Applications 18

Maps and locations Activity code GoogleMap map = ((MapFragment) getfragmentmanager().findfragmentbyid(r.id.map)).getmap() The object GoogleMap can now be modified to move the camera, make zoom, add markers, etc OSSCOM Programming Mobile Applications 19

Maps and locations Adding markers final LatLng ESII = new LatLng(38.97878612469428, -1.8558686971664429); map.addmarker(new MarkerOptions().position(ESII).title("University")); Modifying the map visualization map.setmaptype(googlemap.map_type_terrain); map.setmaptype(googlemap.map_type_normal); map.setmaptype(googlemap.map_type_hybrid); map.setmaptype(googlemap.map_type_satellite); OSSCOM Programming Mobile Applications 20

Maps and locations Move the camera to an specific position final LatLng I3A = new LatLng(38.979019654695456, -1.854119896888733); map.movecamera(cameraupdatefactory.newlatlng(i3a)); Disable zoom and other UI settings map.getuisettings().setcompassenabled(true); map.getuisettings().setzoomcontrolsenabled(false); Animate the camera movements map.animatecamera(cameraupdatefactory.zoomto(15), 2000, null); OSSCOM Programming Mobile Applications 21

Sensors.- Using sensors to obtain real-time data In addition to the camera or GPS, we can access to some sensors like the accelerometer, proximity, etc If we want to use a sensor, we should firstly detect if we can access without problems SensorManager msensormanager; msensormanager = (SensorManager) getsystemservice(context.sensor_service); if(msensormanager.getdefaultsensor(sensor.type_magnetic_field)!= null Toast.makeText(this,"Sucess", Toast.LENGTH_SHORT).show(); else Toast.makeText(this,"Fail", Toast.LENGTH_SHORT).show(); OSSCOM Programming Mobile Applications 22

Sensors.- Using sensors to obtain real-time data Sensors are usually managed to monitor some events For instance: check that the temperature is below certain threshold We need to implement 2 callback methods by making our activity implement the class SensorsEventListener onaccuracychanged() onsensorchanged() We need also register a SensorEventListener for an specific sensor registerlistener(sensoreventlistener l, Sensor s, int rate); OSSCOM Programming Mobile Applications 23

Sensors.- Using sensors to obtain real-time data Sensor Coordinate System OSSCOM Programming Mobile Applications 24

Sensors.- Using sensors to obtain real-time data Some basics Register just the sensors that are needed Unregister the listeners as soon as possible Test your code on real devices, not the emulator Verify sensors before using them OSSCOM Programming Mobile Applications 25

Sensors.- Using sensors to obtain real-time data Example A.- Accessing the accelerometer Detect shake movements Detect steps Draw figures on the air... OSSCOM Programming Mobile Applications 26

Sensors.- Using sensors to obtain real-time data Example A.- Accessing the accelerometer Global Variables private SensorManager msensormanager; private Sensor maccelerometer; Initialization msensormanager = (SensorManager) getsystemservice(context.sensor_service); maccelerometer = msensormanager.getdefaultsensor(sensor.type_accelerometer); msensormanager.registerlistener(this, maccelerometer, SensorManager.SENSOR_DELAY_NORMAL); OSSCOM Programming Mobile Applications 27

Sensors.- Using sensors to obtain real-time data Example A.- Accessing the accelerometer Capture the changes public void onsensorchanged(sensorevent event) { float x = event.values[0]; float y = event.values[1]; float z = event.values[2]; } Unregistering on pause protected void onpause() { super.onpause(); msensormanager.unregisterlistener(this); } OSSCOM Programming Mobile Applications 28

Sensors.- Using sensors to obtain real-time data Example B.- Accessing the proximity sensor Global Variables private SensorManager msensormanager; private Sensor mproximitysensor; Initialization msensormanager = (SensorManager) getsystemservice(context.sensor_service); mproximitysensor = msensormanager.getdefaultsensor(sensor.type_proximity); msensormanager.registerlistener(this, mproximitysensor, SensorManager.SENSOR_DELAY_NORMAL); OSSCOM Programming Mobile Applications 29

Sensors.- Using sensors to obtain real-time data Example B.- Accessing the proximity sensor Capture the changes public void onsensorchanged(sensorevent event) { Toast.makeText(this, "Distance "+String.valueOf(event.values[0]), Toast.LENGTH_SHORT).show(); } Unregistering on pause protected void onpause() { super.onpause(); msensormanager.unregisterlistener(this); } OSSCOM Programming Mobile Applications 30

External Data.- How to access files, databases and content providers Not all the data included in our applications can be stored when released Size requirements Dynamic changes We can find several alternatives OSSCOM Programming Mobile Applications 31

External Data.- Alternatives Shared Preferences Store private primitive data in key-value pairs. Internal Storage Store private data on the device memory. External Storage Store public data on the shared external storage. SQLite Databases Store structured data in a private database. Network Connection Store data on the web with your own network server. OSSCOM Programming Mobile Applications 32

External Data. Shared Preferences This is the most basic type of storage and allows to save any type of primitive data Save SharedPreferences settings = getsharedpreferences( TempusPref, 0); SharedPreferences.Editor editor = settings.edit(); editor.putboolean("myboolvar", true); editor.commit(); Load SharedPreferences settings = getsharedpreferences( TempusPref, 0); boolean varloaded = settings.getboolean("myboolvar", false); setboolvar(varloaded); OSSCOM Programming Mobile Applications 33

External Data. Internal Storage Similar to the file access in other programming environments Files saved with our applications cannot be accessed by the rest of the applications (by default) String FILENAME = "filetosave"; String string = "text to save"; FileOutputStream fos = openfileoutput(filename, Context.MODE_PRIVATE); fos.write(string.getbytes()); fos.close(); OSSCOM Programming Mobile Applications 34

External Data. External Storage Files that need to be written in external SD cards or similar, instead of internal storage We need additional permissions to access external storage <uses-permission android:name="android.permission.write_external_storage" /> OSSCOM Programming Mobile Applications 35

External Data. Databases Similar to the web pages, all the dynamic content of an android application can be obtained from a database The technology used for most Android applications is SqlLite, with considerable differences with respect to traditional databases languages Network Connections We can use the network connections to obtain data from the Internet, as we did to obtain images OSSCOM Programming Mobile Applications 36

External Data. Content Providers Access to structured sets of data Permission management Key elements ContentResolver For the access to content providers URI Identification of content providers Basis steps to retrieve data from a content provider Request the read access permission for the provider. Define the code that sends a query to the provider. OSSCOM Programming Mobile Applications 37

External Data. Content Providers Request the read access permission for the provider. Using the manifest file <uses-permission android:name="android.permission.read_user_dictionary"> Define the code that sends a query to the provider. ContentResolver.Query() Insert data Update data Delete data OSSCOM Programming Mobile Applications 38

External Data. Content Providers Data types: integer, long integer (long), floating point, long floating point (double) Building a content provider is a complex task and needs to be performed only when necessary Design data storage Design content URIs Implement the ContentProvider Class Implement the ContentProvider MIME types Permissions and Access OSSCOM Programming Mobile Applications 39

External Data. Content Providers.- Contact providers Android component for the management of our contacts Three types of data about a person Basic steps to retrieve a list of contacts Permissions <uses-permission android:name="android.permission.read_contacts" /> Define layout elements for visualization Follow the guidelines from http://developer.android.com/training/contacts-provider/retrieve-names.html OSSCOM Programming Mobile Applications 40

Android Lab V.- Create, compile and execute an advanced application with localization, external storage and sensors processing. Follow the instructions to create an application with access to the Google Maps Api with sensor processing and external storage of data OSSCOM Programming Mobile Applications 41

Programming Mobile Applications 22-26 September, Albacete, Spain Jesus Martínez-Gómez