Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

Next time...

Next time on

Android Bootcamp:

Data and Communication

Android Bootcamp Week 4

Using the Camera

https://github.com/ThoughtWorksAustralia/AndroidBootcampProject#week-4-using-the-camera

Last week:

  • We discussed the principles of layout and design in Android

  • We modified the layout of our app to give it a better look and loaded / displayed the grid of treasure photos

This week:

  • We will use the devices camera to take a photo

  • We will then compare the taken photos location with the selected treasure location and calculate the distance between the two

Exercise 4: Check the Location

Retrospective...

1. Create a new function that will get the location info from a given image path

2. Use the built in Android class ExifInterface to retrieve the photos Exif geo information

3. With the retrieved locations create a new function that will calculate the distance between to latitude longitude locations (Hint. See the built in Location class)

4. Create a Toast to tell the user how far away they are from the Treasure!

Summary

  • What did we do well?
  • What could we do better?
  • What puzzles you?

Exercise 3: Get the captured photo

Sometimes you need to tell the Service / Activity what to do...

1. In the TreasureListFragment override the method onActivityResult

2. Check that we are handling the right Result and Request

http://developer.android.com/guide/topics/media/camera.html#intent-receive

In our case the camera app can either take a photo or a video

Exercise 2: Take a Photo

1. Create a new function that is called from our onItemClicked Listener i.e. void takePhoto()

2. In this function create a new Intent specifying that you want to perform the action MediaStore.ACTION_IMAGE_CAPTURE

3. Create the file we want to save the photo to

  • Always use the built in camera app unless you have a really good reason not to
  • You can invoke both internal Activities and external apps via the intent system
  • Android provides a vast API - make sure you read up on it!

Hard way

4. Make sure you store this location so we can refer to it later!

5. Register the file location with the Intent (intent.putExtra)

6. Start the Activity

Exercise 1: Register a Click Listener

1. Go to the TreasureListFragment class and register an onItemClickedListener on the GridView we created previously

2. Store the path of the taken photo so we can use it later

To do this you will also need to have a reference to the TreasureListAdapter so that you can call the method getItem(itemPosition) to retrieve the selected photo path

Before the exercises

Before the exercises part 2

What happens if there are multiple handlers?

Geo tagging and Location

More on Intents

Types

Two types of Intents

  • Explicit - You know exactly which class you want
  • Implicit - You know the action that you want to do

Intents

What's Exif?

Please add these two lines below to your applications build.gradle which is located here:

/AndroidBootcamp/build.gradle

1. Inside the dependencies block:

classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.9.+'

2. And before the apply plugin: 'android' directive

apply plugin: 'android-sdk-manager'

Intent Filters

Don't use implicit Intents for Services!

There is no guarantee which service will actually respond to your request!

Messaging object used to request an action from another app component.

How does the Android system know which Activities / Services provide which actions?

  • Filters allow you to specify which Actions your activity or service respond to

Easy way

Exchangeable image file format

  • Standard that specifies the format of Images
  • Additionally defines metadata format
  • Start an Activity
  • Start a Service
  • Deliver a Broadcast

3. Optional: Create a ContextMenu instead

Reading EXIF data - ExifInterface

http://developer.android.com/reference/android/view/ContextMenu.html

  • Install google play services, Download this file: http://goo.im/gapps/gapps-jb-20130813-signed.zip
  • Drag the downloaded zip onto your running Genymotion emulator
  • Ignore any errors and restart the emulator
  • Now using the playstore in your emulator find the App called Camera MX and install it

  • Simple API built into Android
  • Provides access to meta info such as DateTime GPS coordinates

Example: Selecting a contact

Use whats already installed on the phone!

  • Most if not all phones have a default camera app

Create an Intent which contains the action you wish to perform

Location

A note on Toasts

Example: Where is my contact?

All we have to do is

  • Ask the phone to use the camera
  • Receive a call back when the user has taken a photo
  • Then do something with the image

In Android if you want to give the user a brief message about something you can use something that is called a Toast message

If the Activity you sent the Intent to returns a result it will also use the Intent API to send the result back to you

Built in Location API (android.location)

  • Lower level API
  • Use only if you need to

To receive this result simply override the method onActivityResult

Google Play Services Location API

  • Improved location services introduced recently
  • We will discuss in more detail in Week 6

Hard way - Build a Camera App

Use it if you

  • need the camera app to be styled a certain way
  • need custom functions or behaviors

But...

  • It requires a bit of code...

http://developer.android.com/guide/topics/media/camera.html#custom-camera

Using the Camera...

design by Dóri Sirály for Prezi

Learn more about creating dynamic, engaging presentations with Prezi