Google maps + GPS,
camera, SD card
Nikola Kapraljević
Infinum Ltd.
About me

twitter@nixa
nikola.kapraljevic@gmail.com
Android
Ruby on Rails
iPhone
About Infinum Ltd.

www.infinumdigital.com
Mobile and web development company
10 people
Offices in Ljubljana and Zagreb
Google Maps API + GPS
Google APIs Add-On

be careful when testing
examples you’ll need
emulator with “Google
APIs”
maps don’t work
offline
New project ...
Google APIs not Android x.x
Maps API key
register for Maps API key
http://code.google.com/android/maps-api-signup.html


nixa-macbook:~ nixa$ keytool -list -keystore .android/
debug.keystore
Enter keystore password: android
Your keystore contains 1 entry
Certificate fingerprint (MD5): 43:9D:9B:
48:83:27:69:02:21:61:78:A7:F5:01:7D:F7
Maps API key


place api key in something like prefs.xml
production/development keys are different
AndroidManifest.xml
MapActivity
main.xml
android:clickable=”true”
Controlling MapView
shows map
MapController controls the map
MapController controller = map.getController()
controller.setZoom(10)
controller.setCenter(GeoPoint gp)
controller.animateTo(GeoPoint gp)
MyLocationOverlay

myLocationOverlay = new MyLocationOverlay(this,
map);
myLocationOverlay.runOnFirstFix(Runnable r)
myLocationOverlay.enableMyLocation()
myLocationOverlay.disableMyLocation()
CustomLocationOverlay
extend MyLocationOverlay for custom POI icon
POIs on MapView

MyPOIOverlay extends ItemizedOverlay<OverlayItem>
similar to ArrayAdapter
override
  protected OverlayItem createItem(int i)
  public int size()
boundCenterBottom(Drawable)
keep local copy of data in overlay in case you need to show
some info for POI
MapViewBallons
https://github.com/jgilfelt/android-mapviewballoons
GPS ...
and why I hate GPS
Permissions

First you’ll need permissions
  INTERNET
  ACCESS_FINE_LOCATION
  ACCESS_COARSE_LOCATION
Sometimes users complain about FINE_LOCATION.
Use only if you really need it.
LocationManager

Context.getSystemService(Context.LOCATION_SERVICE)
GPS_PROVIDER
NETWORK_PROVIDER (cell tower and Wi-Fi based
location)
locationManager.requestLocationUpdates(LocationManag
er.NETWORK_PROVIDER, time, distance,
locationListener);
LocationListener

 void onLocationChanged(Location location)
 void onProviderDisabled(String provider)
 void onProviderEnabled(String provider)
 void onStatusChanged(String provider, int status,
 Bundle extras)
GPS testing
Emulator
  telnet localhost 555x
  geo fix 45.0 22.0
Device
  My Fake Location com.my.fake.location
  Applications -> Development -> Allow mock locations
GPS more info

http://developer.android.com/guide/topics/location/
obtaining-user-location.html
http://stackoverflow.com/questions/3145089/what-is-
the-simplest-and-most-robust-way-to-get-the-users-
current-location-in-a/3145655#3145655
we use this in most of our applications
Camera
Permissions

<uses-permission
android:name="android.permission.CAMERA" />
 <uses-feature
android:name="android.hardware.camera" />
 <uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
Camera via Intent

 Intent intent = new
 Intent(MediaStore.ACTION_IMAGE_CAPTURE);
 //extra to save full-image somewhere
 intent.putExtra(MediaStore.EXTRA_OUTPUT,
 Uri.fromFile(destination));
 destination = new
 File(Environment.getExternalFilesDir(null),"image.jpg");
Camera via SurfaceHolder


for creating camera applications etc...
in 99% cases you don’t need this
http://developer.android.com/reference/android/
hardware/Camera.html
Crop



doesn’t work on all devices!
Crop
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 116);
intent.putExtra("outputY", 116);
intent.putExtra("return-data", true);


Bitmap userImage = (Bitmap) data.getExtras().get("data");
SD card
SD card

<uses-permission
android:name="android.permission.WRITE_EXTERNAL
_STORAGE" />
Include an empty file named .nomedia in your external
files directory (note the dot prefix in the filename). This
will prevent Android's media scanner from reading your
media files and including them in apps like Gallery or
Music.
SD card

Check for presence and availability before using SD
  String state = Environment.getExternalStorageState();
    MEDIA_MOUNTED
    MEDIA_MOUNTED_READ_ONLY
External folders
 File getExternalStoragePublicDirectory (String type)
    DIRECTORY_MUSIC, DIRECTORY_PODCASTS,
    DIRECTORY_RINGTONES, DIRECTORY_ALARMS,
    DIRECTORY_NOTIFICATIONS, DIRECTORY_PICTURES, or
    DIRECTORY_MOVIES
    gets scanned by media scanner
    files aren’t deletes on app uninstall
 File getExternalFilesDir (String type)
    doesn’t get scanned by media scanner
    files are deleted on app uninstall
App 2 SDcard


<manifest xmlns:android="http://
schemas.android.com/apk/res/android"
android:installLocation="preferExternal" ... >
use location “auto”
Tips & tricks
Droidscreen
https://github.com/ribomation/DroidAtScreen1
Emulator sucks.
Google Analytics also suck.
Use Flurry.
Use version control.
Once again, use version
control!
Use drawable selectors.
different images for normal and pressed state
Test on crapy devices.
Threads are you friends.
runOnUiThread, Handler
Check out Fragments.
They’re cool!
SDK/tools/layoutopt
Standardise your res/*
naming convention
Designing app for landscape
mode is 2x the work.
Use Dev Tools
ICS devices
coloredlogcat.py
http://jsharkey.org/blog/2009/04/22/modifying-the-
android-logcat-stream-for-full-color-debugging/
Pitanja ...

More Related Content

PPTX
Developing AIR for Android with Flash Professional
PDF
What is image in Swift?/はるふ
PDF
Mopcon2017 - AppDevKit x CameraKit
PDF
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
KEY
Appcelerator iPhone/iPad Dev Con 2010 San Diego, CA
ZIP
iPhone/iPad Development with Titanium
PDF
臉 - The Face Detection Functions on Android
PDF
Easy path to machine learning
Developing AIR for Android with Flash Professional
What is image in Swift?/はるふ
Mopcon2017 - AppDevKit x CameraKit
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
Appcelerator iPhone/iPad Dev Con 2010 San Diego, CA
iPhone/iPad Development with Titanium
臉 - The Face Detection Functions on Android
Easy path to machine learning

Similar to Google maps and GPS, camera, SD card, tips &amp; tricks (20)

KEY
Android tips and tricks
PPTX
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
PPT
Porting and Maintaining your C++ Game on Android without losing your mind
PPTX
Developing AIR for Mobile with Flash Professional CS5.5
PDF
Introduction to Android - Mobile Portland
PDF
Getting Started with Android - OSSPAC 2009
PDF
Using Android Things to Detect & Exterminate Reptilians
PDF
Introduction to Cloud Computing with Google Cloud
PDF
Node in Production at Aviary
PDF
@Ionic native/google-maps
PDF
[IO Extended KL] On-Device AI: Is It Time to Go All-In, or Do We Still Need t...
ODP
Non Conventional Android Programming En
ODP
Non Conventional Android Programming (English)
PPTX
JS digest. February 2017
PPTX
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
PDF
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
PDF
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
PDF
android_project
PPTX
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
PPTX
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Android tips and tricks
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Porting and Maintaining your C++ Game on Android without losing your mind
Developing AIR for Mobile with Flash Professional CS5.5
Introduction to Android - Mobile Portland
Getting Started with Android - OSSPAC 2009
Using Android Things to Detect & Exterminate Reptilians
Introduction to Cloud Computing with Google Cloud
Node in Production at Aviary
@Ionic native/google-maps
[IO Extended KL] On-Device AI: Is It Time to Go All-In, or Do We Still Need t...
Non Conventional Android Programming En
Non Conventional Android Programming (English)
JS digest. February 2017
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
android_project
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Ad

Google maps and GPS, camera, SD card, tips &amp; tricks

Editor's Notes