google maps api

48
www.greenITcenter.org DUE 0903239 Google Maps API

Upload: kisha

Post on 23-Feb-2016

106 views

Category:

Documents


0 download

DESCRIPTION

Google Maps API. Google Maps on Android. A nice API for mapping applications. Pre- reqs. Need to have the Google API added in Eclipse’s Android Manager Make sure your build target and Android Virtual Device (AVD, or the simulator) support the maps More info: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Google Maps API

www.greenITcenter.org DUE 0903239

Google Maps API

Page 2: Google Maps API

www.greenITcenter.org

Google Maps on Android

A nice API for mapping applications

Page 3: Google Maps API

www.greenITcenter.org

Pre-reqs

Need to have the Google API added in Eclipse’s Android Manager

Make sure your build target and Android Virtual Device (AVD, or the simulator) support the maps

More info:

http://developer.android.com/resources/tutorials/views/hello-mapview.html

Page 4: Google Maps API

www.greenITcenter.org

Add the MapView

In the res/layout/main.xml file: Add your MapView

Details in the Tutorial

http://developer.android.com/resources/tutorials/views/hello-mapview.html

Page 5: Google Maps API

www.greenITcenter.org

A Key

You will need a Google Maps API Key

It’s free - you can register with the SDK debug certificate. When deploying your app for real, you’ll need a

real certificate

http://code.google.com/android/add-ons/google-apis/mapkey.html

Page 6: Google Maps API

www.greenITcenter.org

Using the Map Controller

Using the Map is easy… MapController myMC =

myMapView.getController();

myMC.setZoom(17); // set the zoom level myMapView.setSatellite(); // sets sat view

Page 7: Google Maps API

www.greenITcenter.org

Map Control

You can zoom, set points, routes, etc.

Adding overlays allows you to note all places of interest from a list

Overlays are discussed in the tutorial http://

developer.android.com/resources/tutorials/views/hello-mapview.html

Page 8: Google Maps API

www.greenITcenter.org DUE 0903239

Intents

Page 9: Google Maps API

www.greenITcenter.org

Intents

Intents allow you to pass a message Within your app To existing resources on the phone, such as the dialer

Page 10: Google Maps API

www.greenITcenter.org

Uses

To launch the dialer… To load another activity in your app… You can also create custom intents…

Page 11: Google Maps API

www.greenITcenter.org

Launch another Activity

Intent intent = new Intent(FirstActivity.this, AnotherActivity.class);        startActivity(intent);

This will launch another activity (screen) without destroying the first

Page 12: Google Maps API

www.greenITcenter.org

ExampleIntent I = new Intent(Intent.ACTION_DIAL, Uri.parse(“tel:647-722-3888”));

startActivity(i);

Page 13: Google Maps API

www.greenITcenter.org

Launch Google MapsString uri = “geo:37.523156,-121.084917”

Intent myIntent = New Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));

startActivity(myIntent);

Page 14: Google Maps API

www.greenITcenter.org

Intents can

Return a result. startActivityForResult();

Be filtered by your app so that you can respond to certain intents.

Create your own and respond to them

Page 16: Google Maps API

www.greenITcenter.org DUE 0903239

Files and Storage on Android Devices

Page 17: Google Maps API

www.greenITcenter.org

Storage

Four basic ways

Shared Preferences Database Files on the Device The “cloud”

http://developer.android.com/guide/topics/data/data-storage.html

Page 18: Google Maps API

www.greenITcenter.org

Shared Preferences

Easy, built in way to save preferences to the device App settings, Similar to the Windows registry SharedPreferences class in the API

Page 19: Google Maps API

www.greenITcenter.org

SharedPreferences Example SharedPreferences settings =

getSharedPreferences(PREFS_NAME, default_value);

boolean value = settings.getBoolean(“prefName", default_value);

Page 20: Google Maps API

www.greenITcenter.org

Database

Local database on the device SQLite For heavier-duty data requirements / queries

db.execSQL(“SELECT * …”);

Page 21: Google Maps API

www.greenITcenter.org

Files

Can store data to a file Useful for saving media files, save games,

etc. Just like writing files in Java

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);

fos.write(string.getBytes());

fos.close();

Page 22: Google Maps API

www.greenITcenter.org

Saving to the Network Persistent storage, but… A network connection

may not always be available

May have to create your own server

android.net libraries stream to a network connection

Page 23: Google Maps API

www.greenITcenter.org

Amazon AWS

Allows you to save data to Amazon servers

An API for Android

http://aws.amazon.com/

Page 24: Google Maps API

www.greenITcenter.org

OpenFeint & Scoreloop

A nice resource for games Allows you to easily save high scores and

achievements Creates leaderboards, friend lists, etc.

www.OpenFeint.com www.ScoreLoop.com

Page 25: Google Maps API

www.greenITcenter.org DUE 0903239

Broadcast Receivers

Page 26: Google Maps API

www.greenITcenter.org

Broadcast Receivers

These allow you to ‘intercept’ messages That you create, or… That the system sends

Page 27: Google Maps API

www.greenITcenter.org

The coolest part

The user doesn’t need to start your app

If your receiver listens for the specific Intent that fired, that code will run

Or you can decide when a receiver is active through registering / deregistering

Page 28: Google Maps API

www.greenITcenter.org

2 ways to create

In xml <receiver> tag in AndroidManifest.xml

In Code Context.registerReceiver(); Gives more control, but not active until your app

has run

Page 29: Google Maps API

www.greenITcenter.org

Then…

Just fill in the onReceive() method.

This is the code that “handles” the event

Page 30: Google Maps API

www.greenITcenter.org

Some System Intents

ACTION_TIME_TICK A minute has passed

ACTION_BATTERY_LOW Need to plug it in!

SMS_RECEIVED You got a text!

Page 32: Google Maps API

www.greenITcenter.org DUE 0903239

Android Databases

Page 33: Google Maps API

www.greenITcenter.org

Databases

Android uses the SQLite Database

A lightweight database server

Returns the Android ‘Cursor’ instead of rows – for efficiency.

Page 34: Google Maps API

www.greenITcenter.org

Basics

It’s useful to create a “Helper” class to simplify database interactions

Methods will include: getRecord(long rowIndex) to return a specific

record getAllRecords() to return a Cursor

Page 35: Google Maps API

www.greenITcenter.org

SQLiteOpenHelper

Your helper class can also extend the SQLiteOpenHelper abstract class

To simplify creating and opening databases

Page 36: Google Maps API

www.greenITcenter.org

Cursors

Instead of returning rows, you get a Cursor to manage the results of a query

Cursor myResult = myDB.query (…);

myResult.getString(columnIndex);

Page 37: Google Maps API

www.greenITcenter.org

Notepad Tutorial

Great tutorial for database concepts

Includes: Integrating the ListView with a DB ->

http://developer.android.com/resources/tutorials/notepad/index.html

Page 38: Google Maps API

www.greenITcenter.org DUE 0903239

Publishing Your Apps

Page 39: Google Maps API

www.greenITcenter.org

Signing

This is required to release your application

Several Steps…

The tutorial http://developer.android.com/guide/publishing/app-signing.html

Page 40: Google Maps API

www.greenITcenter.org

Apps

The device will only run signed apps

You can issue your own certificate, or use the developer certificate for testing

To release, you must have a certificate with a 20+ year expiration date

Page 41: Google Maps API

www.greenITcenter.org

Eclipse

Right-click on the project Android Tools -> Export Signed Application This creates the .apk You can then load it to a web server

Page 42: Google Maps API

www.greenITcenter.org

Device

Make sure your device allows apps that are not from the app store

In configuration menu

Page 43: Google Maps API

www.greenITcenter.org

Testing… Very important!

Test on several devices Screen resolutions No network connectivity Orientation Interruption from calls GPS if applicable

The simulator is usually a best-case scenario!

Page 44: Google Maps API

www.greenITcenter.org

Simulator

Test on all available AVD versions

Specify the <uses-sdk> parameter in the manifest, and test on all devices after that version

Page 45: Google Maps API

www.greenITcenter.org

Simulator

In Eclipse’s Run->Run Configuration Specify Network speed and latency to test

under varying conditions Test on a real device also

Page 46: Google Maps API

www.greenITcenter.org

Once fully tested

Submit to the Android Marketplace

Should obfuscate source code Harder to reverse engineer Proguard does the trick

Enabled in eclipse – your app will have a proguard.cfg file

Page 47: Google Maps API

www.greenITcenter.org

Submission

Google charges $25 to register You may then submit as many apps as you

like Activation in the Google marketplace is

almost instantaneous

Amazon AppStore takes 2-3 weeks for approval

Page 48: Google Maps API

www.greenITcenter.org

Proguard Documentation

http://developer.android.com/guide/developing/tools/proguard.html

Shrinks, optimizes, and obfuscates the code