Sensors, maps and fragments:

Slides:



Advertisements
Similar presentations
Android Application Development Tutorial. Topics Lecture 4 Overview Overview of Sensors Programming Tutorial 1: Tracking location with GPS and Google.
Advertisements

Lecture 6 Testing and Debugging on a Physical Android Device and other Power User Stuff.
CE881: Mobile and Social Application Programming Simon M. Lucas Menus and Dialogs.
Location based services
Prepared by: Prepared by: Jameela Rabaya Jameela Rabaya Fatima Darawsha Fatima Darawsha.
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
Location and Maps Content Getting Location Getting Google Map In application Test on Emulator/Device.
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
Setting up the Development Environment Copyright © SUPINFO. All rights reserved Preparation.
How to make it work? Doncho Minkov Telerik Academy academy.telerik.com Technical Trainer
SET UP COMPUTER ** PLEASE BE AWARE SCREENSHOTS MAY NOT MATCH **
Route Tracker App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Google Maps Android API v2 吳俊興 國立高雄大學 資訊工程學系 CSF645 – Mobile Computing 行動計算
December 10th Inservice Presenter: Linda Lopresti 9-10 English Department (K112) Contact Info: twitter:
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
Location based services Using Google Maps v2 etc. in Android apps 1Location based services.
Location based services
1 Mobile Computing Monetizing An App Copyright 2014 by Janson Industries.
Chapter 2: Simplify! The Android User Interface
PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse 
Copyright© Jeffrey Jongko, Ateneo de Manila University Android.
DUE Hello World on the Android Platform.
26/05/2016 E.R.Edwards 26/05/2016 Staffordshire University School of Computing Introduction to Android Practical 1 Changing the Eclipse Workspace Importing.
Android for Java Developers Denver Java Users Group Jan 11, Mike
1 CMSC 628: Introduction to Mobile Computing Nilanjan Banerjee Introduction to Mobile Computing University of Maryland Baltimore County
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Presented By: Muhammad Tariq Software Engineer Android Training course.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
© by Pearson Education, Inc. All Rights Reserved. 1 Introduction to Android From “Android: How to Program” By Paul Deitel and Harvey Deitel.
Android Boot Camp for Developers Using Java, 3E
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Android Hello World 1. Click on Start and type eclipse into the textbox 2.
MAKANI ANDROID APPLICATION Prepared by: Asma’ Hamayel Alaa Shaheen.
Location. GPS Global Positioning System – At least 4 satellites typically used 3 required extra for error detection and altitude typically accurate within.
First Venture into the Android World Chapter 1 Part 2.
Mobile Application Development with ANDROID Umang Patel(6537) LDCE.
DEVOLOPING ANDROID APP ON LOCATION BASED REMINDER ON ANDROID MOBILE SYSTEMS.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
Chapter 6 Google Play Services GOALS & OBJECTIVES Google Play Services give you features to attract users using Google features such as Google Maps, Google+,
Accelerometer based motion gestures for mobile devices Presented by – Neel Parikh Advisor Committee members Dr. Chris Pollett Dr. Robert Chun Dr. Mark.
How to Sync Android Phone to Computer (PC/Mac)? Are you a person that always has your Android phone in your hands? Nowadays, a cell phone is not just for.
1. 2 Android location services Determining a device’s current location Tracking device movements Proximity alerts.
CS499 – Mobile Application Development Fall 2013 Location & Maps.
Day 1 Session 2. Setup & Installation
Introduction to Android Programming
Mobile Device Development
Chapter 2: Simplify! The Android User Interface
Android Mobile Application Development
Installation The Intercompany Integration Solution for SAP Business One Version 2.0 for SAP Business One 9.1 Welcome to the course on the installation.
Android 01: Fundamentals
Android Application Development 1 6 May 2018
Obtaining the Required Tools
AnDroid GoogleMaps API
Android Studio, Android System Basics and Git
Computing.
Android.
Mobile Application Development Chapter 5 [Persistent Data in Android]
Development-Introduction
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Vijay Kumar Kolagani Dr. Yingcai Xiao
Chapter 15: App Monetization Strategies
Installation The Intercompany Integration Solution for SAP Business One Version 2.0 for SAP Business One 9.1 Welcome to the course on the installation.
Vijay Kumar Kolagani Dr. Yingcai Xiao
Welcome to E-Prime E-Prime refers to the Experimenter’s Prime (best) development studio for the creation of computerized behavioral research. E-Prime is.
Application Development A Tutorial Driven Course
Android Programming Tutorial
Cosc 4730 An Introduction.
Presentation transcript:

Sensors, maps and fragments: Sensors are hardware built in to the mobile device to allow an app to capture environmental data. 2 location sensors are in Android devices. Network sensor based on cell towers/WiFi. Sensor based on Global Positioning Services (GPS). Figure: From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Accessed through the method getSystemService . Location information is accessed within an app through the use of the LocationManager object. Accessed through the method getSystemService . The LocationManager object requests updates from either or both sensors. To get the updates, an app has to instantiate a LocationListener. A LocationListener implements the method onLocationChanged. Change reported by sensors is captured by the LocationListener, which is passed a Location object. A Location object has information on the new location, including GPS coordinates and altitude, which sensor provided the location, a measure of the accuracy of the coordinate estimate, etc. The onLocationChanged performs operations based on developer code. To receive information from the sensors, the LocationManager requests the updates from providers and indicates what LocationListener to use to handle the updates. When the LocationManager requests updates from the GPS, the GPS is activated. Figure: From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Sensors, maps and fragments (Cont): Maps are used to display data that can be enhanced by a visual representation of its location. Maps are implemented using the GoogleMap object in the source code file and a MapFragment in the layout file. Google Play Services SDK is installed on your development machine to implement maps in your app. Using Google Maps requires an API key, which is free. Maps are implemented as a MapFragment widget in a layout. The Activity that implements the code for the map’s behavior is a FragmentActivity. Figure: From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Sensors, maps and fragments (Cont): Fragments are used in coding Android Activities. The FragmentActivity is a subclass of the Activity class. Activities that implement a map must extend the FragmentActivity class not the Activity class. This is because maps are enclosed in a MapFragment . This allows a map to be a part of a layout not the only thing in a layout. To set up for Maps: Load the Google Play Services SDK into your workspace. Select Window > Android SDK Manager. Scroll through the list of available SDKs to the Extras folder. Check the box next to Google Play Services. Accept license and install. Figure: From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Figure 7.1 Android SDK Manager window. The process of updating or adding SDKs to Eclipse is known to be “buggy.” Figure: Figure 7.1 Android SDK Manager window. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

After you accept license and install follow the prompts to add the Google Play Services SDK to your project. Figure: Figure 7.2 Choose Packages window. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

The Google Services Library is in the bottom window. Click OK to close the Properties window, add the API key next. Figure: Figure 7.3 Adding Google Play Services to project. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Copy the API key into your app manifest file. Go to the Google API Console and enter the fingerprint to get the API key. Copy the API key into your app manifest file. Figure: Figure 7.4 Get SHA1 fingerprint. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Figure 7.5 Initial Layout for getting location. Open the AndroidManifest.xml file and enter the permissions in Listing 7.1 Find your location: use the map’s getMyLocation ( ) method to get the device’s current GPS coordinates. Refer to Figure 7.5 to code this layout. Figure: Figure 7.5 Initial Layout for getting location. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Figure 7.5 Initial Layout for getting location. After layout creation open the ContactMapActivity.java file to write the code for the behavior for the Get Location button. Refer to Listing 7.2 to write this code. Code the call to the initialization method in the onCreate method. The proper format for a call is required i.e. street address method. A List object variable parameterized to hold an Address object is declared. A Geocode variable is declared and assigned a new Geocoder object. The getFromLocationName method is used as a parameter. The latitude and longitude of the first address in the returned list are displayed. Figure: Figure 7.5 Initial Layout for getting location. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Get coordinates from the GPS sensor. Replace the Geocoding code in the Get Location button with GPS listener code. Refer to Listing 7.3 Users get a reference to the system’s location manager and instantiates a location listener to get the GPS coordinates. Refer to Listing 7.4 for overriding onPauses method. Be sure to change the location of the emulator. Figure: Figure 7.6 Emulator location control. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

The Android Device Chooser Window is displayed ( Figure 7.7 ). To test the code on a device that has a GPS, terminate the app running on the emulator (Run > Terminate) and plug an Android device into the computer. 1. Open Debug Configurations (Run > Debug Configurations). Select your debug configuration and then click the Target tab. 2. Select Always Prompt to Pick Device. Press the Apply button and then the Debug button. The Android Device Chooser Window is displayed ( Figure 7.7 ). Figure: Figure 7.7 Device Chooser window. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Once the GPS sensor is working, changing or adding a network sensor is easy. Use this declaration: LocationListener networkListener ; Refer to Listing 7.5 Figure: Figure 7.7 Device Chooser window. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Refer to Listing 7.6 – 7.13 to code for Map of contacts with marker information displayed (see figure 7.8). Figure: Figure 7.8 Map of Contacts with marker information displayed. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

The Android platform supports 12 sensors. Check for sensors before use. The Sensor class represents all types of sensors. Sensors are accessed through the SensorManager class. SensorEvent and SensorEventListener are also required. Figure: Figure 8.1 Toolbar with battery level TextView. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Android devices have managers for monitoring: BatteryManager used to monitor the battery’s status. StorageManager used to monitor long-term storage. PowerManager used to monitor power consumption. Android devices have other hardware features like a phone or a camera with apps to access their use. Access via Application Program Interface (API). See Listing 8.1 – 8.2 for monitoring the battery with the apps. Figure: Figure 8.1 Toolbar with battery level TextView. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Motion sensors detect how the device is moving. The Android OS supports sensors for motion, environmental, or position. Motion sensors detect how the device is moving. Environmental sensors capture measures of the ambient environment such as light level. Position sensors capture information used to determine the physical position of the device. Figure: Figure 8.2 Toolbar with heading TextView. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

Not all devices have all sensors which has implications for how to code access to the sensors. Understanding how the sensors are accessed is important for apps developed. See Listing 8.3 To monitor sensors aSensorManager object and Sensor objects for each sensor used is required. See Listing 8.4 Implement the SensorEventListener, a class that handles the events from the sensors and takes action on them. See Listing 8.5 Figure: Figure 8.2 Toolbar with heading TextView. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

The app can call contacts by pressing and holding down a phone number. Using the Phone In the MyContactList app code the ContactActivity so pressing and holding one of the contact’s automatically calls that number. This requires accessing the phone’s API and asking it to call the number. See Listing 8.6 and 8.7 The app can call contacts by pressing and holding down a phone number. Figure: Figure 8.3 Layout with ImageButton. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.

To add a photo to a contact in the phone see Listing 8.8 – 8.14 Android devices have a camera that is used independently or integrated into an app. To add a photo to a contact in the phone see Listing 8.8 – 8.14 When done the contact should look like Figure 8.4 below. Figure: Figure 8.4 Contact with a picture. From Learning Mobile App Development by Jakob Iversen and Michael Eierman (ISBN: 032194786X) Copyright © 2014 Pearson Education, Inc. All rights reserved.