google maps api

Post on 23-Feb-2016

106 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

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

www.greenITcenter.org DUE 0903239

Google Maps API

www.greenITcenter.org

Google Maps on Android

A nice API for mapping applications

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

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

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

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

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

www.greenITcenter.org DUE 0903239

Intents

www.greenITcenter.org

Intents

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

www.greenITcenter.org

Uses

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

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

www.greenITcenter.org

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

startActivity(i);

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);

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

www.greenITcenter.org DUE 0903239

Files and Storage on Android Devices

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

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

www.greenITcenter.org

SharedPreferences Example SharedPreferences settings =

getSharedPreferences(PREFS_NAME, default_value);

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

www.greenITcenter.org

Database

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

db.execSQL(“SELECT * …”);

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();

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

www.greenITcenter.org

Amazon AWS

Allows you to save data to Amazon servers

An API for Android

http://aws.amazon.com/

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

www.greenITcenter.org DUE 0903239

Broadcast Receivers

www.greenITcenter.org

Broadcast Receivers

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

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

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

www.greenITcenter.org

Then…

Just fill in the onReceive() method.

This is the code that “handles” the event

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!

www.greenITcenter.org DUE 0903239

Android Databases

www.greenITcenter.org

Databases

Android uses the SQLite Database

A lightweight database server

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

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

www.greenITcenter.org

SQLiteOpenHelper

Your helper class can also extend the SQLiteOpenHelper abstract class

To simplify creating and opening databases

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);

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

www.greenITcenter.org DUE 0903239

Publishing Your Apps

www.greenITcenter.org

Signing

This is required to release your application

Several Steps…

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

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

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

www.greenITcenter.org

Device

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

In configuration menu

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!

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

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

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

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

www.greenITcenter.org

Proguard Documentation

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

Shrinks, optimizes, and obfuscates the code

top related