Android app development course



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

Android Sensor Programming. Weihong Yu

Android Framework. How to use and extend it

Android Sensors. CPRE 388 Fall 2015 Iowa State University

Using Sensors on the Android Platform. Andreas Terzis Android N00b

ELET4133: Embedded Systems. Topic 15 Sensors

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

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

06 Team Project: Android Development Crash Course; Project Introduction

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

Using the Android Sensor API

Using Extensions or Cordova Plugins in your RhoMobile Application Darryn

Programming Mobile Applications with Android

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

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

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

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

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

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

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

Lab 1 (Reading Sensors & The Android API) Week 3

How to develop your own app

Beginning Android Application Development

App Development for Smart Devices. Lec #4: Services and Broadcast Receivers Try It Out

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

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

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

Android Basics. Xin Yang

Android builders summit The Android media framework

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

Android Services. Services

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

Android Concepts and Programming TUTORIAL 1

Android Security Lab WS 2014/15 Lab 1: Android Application Programming

Introduction to NaviGenie SDK Client API for Android

Module 1: Sensor Data Acquisition and Processing in Android

Android Services. Android. Victor Matos

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

Developing Android Apps for BlackBerry 10. JAM854 Mike Zhou- Developer Evangelist, APAC Nov 30, 2012

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

1. Introduction to Android

Android app development course

Now that we have the Android SDK, Eclipse and Phones all ready to go we can jump into actual Android development.

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

A qbit on Android Security

Designing An Android Sensor Subsystem Pitfalls and Considerations

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

Android For Java Developers. Marko Gargenta Marakana

TomTom PRO 82xx PRO.connect developer guide

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

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

WEARIT DEVELOPER DOCUMENTATION 0.2 preliminary release July 20 th, 2013

Performance issues in writing Android Apps

Mobile App Sensor Documentation (English Version)

Android Environment SDK

Android app development course

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

AUTOMATIC HUMAN FREE FALL DETECTION USING ANDROID

An Android-based Instant Message Application

Here to take you beyond Mobile Application development using Android Course details

RingCentral Meetings QuickStart

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

Android Environment SDK

Advantages. manage port forwarding, set breakpoints, and view thread and process information directly

Lecture 1 Introduction to Android

Android on Intel Course App Development - Advanced

Zoom Cloud Meetings: Leader Guide

4. The Android System

Flash Development for Android Cookbook

App Development for Smart Devices. Lec #2: Android Tools, Building Applications, and Activities

An Introduction to Android Application Development. Serdar Akın, Haluk Tüfekçi

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

Sending and Receiving Data via Bluetooth with an Android Device

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL II)

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

Android Development. Marc Mc Loughlin

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

Operating System Support for Inter-Application Monitoring in Android

Hello World. by Elliot Khazon

Frameworks & Android. Programmeertechnieken, Tim Cocx

Developing Android Apps for BlackBerry 10. JAM 354 Matthew Whiteman - Product Manager February 6, 2013

Testing Network Performance and Location Based Services throughout Calling and SMS Applications in Android

Transcription:

Android app development course Unit 7- + Beyond Android Activities. SMS. Audio, video, camera. Sensors 1

SMS We can send an SMS through Android's native client (using an implicit Intent) Intent smsintent = new Intent(Intent.ACTION_SENDTO, Uri.parse("sms:55512345")); smsintent.putextra("sms_body", "Press send to send me"); startactivity(smsintent); SmsManager SmsManager smsmanager = SmsManager.getDefault(); String sendto = "5551234"; String mymessage = "Android supports programmatic SMS messaging!"; smsmanager.sendtextmessage(sendto, null, mymessage, null, null); We must add the following permissions SEND_SMS SMS_RECEIVE 2

SMS SmsManager sendtextmessage(dstaddress, scaddress, text, sentintent, deliveryintent) sentintent: PendingIntent launched either when the SMS has been sent or when it has failed to send deliveryintent: PendingIntent launched when we have the confirmation the SMS has been received sendmultiparttextmessage(... ) senddatamessage(... ) 3

SMS To receive SMS We need a BroadcastReceive registered for the Intent android.provider.telephony.sms_received The message or messages can be found in the Intent's extra, pdus, which we must convert to SmsMessage objects To get the actual text of the message we can use getmessagebody( ) from the SmsMessage class 4

SMS public void onreceive(context _context, Intent _intent) { if ( intent.getaction().equals(sms_received) ) { SmsManager sms = SmsManager.getDefault(); Bundle bundle = intent.getextras(); if ( bundle!= null ) { Object[] pdus = (Object[]) bundle.get("pdus"); SmsMessage[] messages = new SmsMessage[pdus.length]; for (int i = 0; i < pdus.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); for (SmsMessage message : messages) { String msg = message.getmessagebody(); String to = message.getoriginatingaddress(); // Perform whatever action needed... 5

Activity 7.1 7.1.1 Create a BroadcastReceiver to receive SMS 7.1.2 Show the contents of the received SMS using a Toast 7.1.3 Create fake SMS through the DDMS perspective to test the receivers correct behavior 6

Audio, video and camera Android provides support for both audio and video playing and recording. In order to get this done we may use Microphone Speakers Camera Screen There are formats and codecs with native support in Android. You can found the exhaustive list here: http://developer.android.com/guide/appendix/media-formats.html 7

Audio, video and camera Playing audio and video We can play audio and video from Resource files (raw resources) File systems (URIs) Remote streaming (URLs) Using the MediaPlayer class We need an instance of MediaPlayer Call prepare() in the first place to load the player's buffer We must release the previous instance by calling release() 8

Audio, video and camera Particularly, in the case of video It requires a surface to play the video on A Layout containing a VideoView: it already handles a MediaPlayer instance; therefore we only need to initialize the resource to play A Layout containing a SurfaceView: must communicate with the MediaPlayer through a listener that implements SurfaceHolder.Callback 9

Audio, video and camera VideoView VideoView videoview = (VideoView) findviewbyid(r.id.surface); videoview.setkeepscreenon(true); videoview.setvideopath("/sdcard/test2.3gp"); if ( videoview.canseekforward() ) { videoview.seekto(videoview.getduration()/2); videoview.start(); //Playing... videoview.stopplayback(); 10

Audio, video and camera SurfaceView public class MyActivity extends Activity implements SurfaceHolder.Callback { private MediaPlayer mmediaplayer; @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); mmediaplayer = new MediaPlayer(); SurfaceView surface = (SurfaceView) findviewbyid(r.id.surface); SurfaceHolder holder = surface.getholder(); holder.addcallback(this); holder.settype(surfaceholder.surface_type_push_buffers); holder.setfixedsize(400, 300);... 11

Audio, video and camera (cont.)... public void surfacecreated(surfaceholder holder) { mmediaplayer.setdisplay(holder); mmediaplayer.setdatasource("/sdcard/test2.3gp"); mmediaplayer.prepare(); mmediaplayer.start(); public void surfacedestroyed(surfaceholder holder) { mmediaplayer.release(); 12

Audio, video and camera Recording audio and video We can use the phone camera through An implicit Intent to start the native camera app (both audio and video) MediaRecorder Similar to MediaPlayer! Has methods such as prepare(), start(), stop(), release(), etc. We need one of the following permissions (or both) RECORD_AUDIO RECORD_VIDEO 13

Audio, video and camera MediaRecorder We need an instance of MediaRecorder We must configure Recording source Destination file Output format Coding algorithm We must prepare the recorder: call prepare() Use the start() and stop() functions 14

Audio, video and camera MediaRecorder (example) MediaRecorder mediarecorder = new MediaRecorder(); mediarecorder.setaudiosource(mediarecorder.audiosource.mic); mediarecorder.setvideosource(mediarecorder.videosource.camera); mediarecorder.setoutputformat(mediarecorder.outputformat.default); mediarecorder.setaudioencoder(mediarecorder.audioencoder.default); mediarecorder.setvideoencoder(mediarecorder.videoencoder.default); mediarecorder.setoutputfile("/sdcard/myoutputfile.mp4"); mediarecorder.prepare(); mediarecorder.start(); // Recording... mediarecorder.stop(); 15

Audio, video and camera To capture pictures through the phone's camera We can use already implemented camera apps startactivityforresult( new Intent(MediaStore.ACTION_IMAGE_CAPTURE), TAKE_PICTURE ) Manage the camera manually through the Camera class Obtain an instance by calling Camera.open() Configure it using Camera.Parameters Obtain a preview using a SurfaceView + SurfaceHolder.Callback and calling the following method setpreviewdisplay(surfaceholder) 16

Audio, video and camera Example private void takepicture() { camera.takepicture(null, null, jpegcallback); PictureCallback jpegcallback = new PictureCallback() { public void onpicturetaken(byte[] data, Camera camera) { try { outstream = new FileOutputStream("/sdcard/test.jpg"); outstream.write(data); outstream.close(); catch (Exception e) { ; 17

Activity 7.2 7.2.1 Create an Activity with two buttons: play and stop 7.2.2 Create a Service bound to the Activity 7.2.3 Start playing and stop an audio file in the res/raw directory by using a MediaPlayer inside the Service 7.2.4 Test that the Service keeps playing the file even if we close the Activity 18

Sensors Most Android devices have built-in sensors such as accelerometer, gyroscope, magnetometers, illumination sensors, etc. Although typically found in both smartphones and tablets, manufacturers may decide not to include them. We can enforce our application to be installed and therefore executed only on those devices having a specific sensor incorporated throught the Manifest file <uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" /> 19

Sensors SensorManager Handle class for all available sensors on the device We can obtain an instance through getsystemservice(context.sensor_service) It can handle up to 12 different sensors (Complete list) We can retrieve a list of available sensors using List<Sensor> getsensorlist(int type) To receive sensor readings we must implement the SensorEventListener interface 20

Sensors SensorEventListener Allows us to receive sensor readings and react to these Is the only way we can retrieve readings from the sensors We must register and unregister the listener through the SensorManager class register(listener, sensor, timeinterval) unregisterlistener(listener) We must implement the following methods onsensorchanged(sensorevent) onaccuracychanged(sensor, accuracy) 21

Sensors public class SensorActivity extends Activity implements SensorEventListener { private final SensorManager msensormanager; private final Sensor maccelerometer; public SensorActivity() { msensormanager = (SensorManager) getsystemservice(sensor_service); maccelerometer = msensormanager.getdefaultsensor( Sensor.TYPE_ACCELEROMETER); protected void onresume() { super.onresume(); msensormanager.registerlistener(this, maccelerometer, SensorManager.SENSOR_DELAY_NORMAL); protected void onpause() { super.onpause(); msensormanager.unregisterlistener(this); 22

Sensors (cont) public void onaccuracychanged(sensor sensor, int accuracy) { public void onsensorchanged(sensorevent event) { float xaxis_laterala = event.values[0]; float yaxis_longitudinala = event.values[1]; float zaxis_verticala = event.values[2]; // Do something with these values... 23

If you want to know more... Professional Android Application Development. Chapters 11, 12 and 14 Pro Android. Chapters 18, 19 i 26 Android Developers: Media and Camera Android Developers: Sensors Overview Capturing Photos 24