SlideShare une entreprise Scribd logo
1  sur  49
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 ...

Contenu connexe

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

Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NCAndroid Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NCJim Tochterman
 
Porting and Maintaining your C++ Game on Android without losing your mind
Porting and Maintaining your C++ Game on Android without losing your mindPorting and Maintaining your C++ Game on Android without losing your mind
Porting and Maintaining your C++ Game on Android without losing your mindBeMyApp
 
Developing AIR for Mobile with Flash Professional CS5.5
Developing AIR for Mobile with Flash Professional CS5.5Developing AIR for Mobile with Flash Professional CS5.5
Developing AIR for Mobile with Flash Professional CS5.5Chris Griffith
 
Introduction to Android - Mobile Portland
Introduction to Android - Mobile PortlandIntroduction to Android - Mobile Portland
Introduction to Android - Mobile Portlandsullis
 
Getting Started with Android - OSSPAC 2009
Getting Started with Android - OSSPAC 2009Getting Started with Android - OSSPAC 2009
Getting Started with Android - OSSPAC 2009sullis
 
Using Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate ReptiliansUsing Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate ReptiliansNilhcem
 
Introduction to Cloud Computing with Google Cloud
Introduction to Cloud Computing with Google CloudIntroduction to Cloud Computing with Google Cloud
Introduction to Cloud Computing with Google Cloudwesley chun
 
Node in Production at Aviary
Node in Production at AviaryNode in Production at Aviary
Node in Production at AviaryAviary
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Davide Cerbo
 
Non Conventional Android Programming En
Non Conventional Android Programming EnNon Conventional Android Programming En
Non Conventional Android Programming Enguest9bcef2f
 
JS digest. February 2017
JS digest. February 2017JS digest. February 2017
JS digest. February 2017ElifTech
 
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...mharkus
 
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...Codemotion
 
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...Codemotion
 
android_project
android_projectandroid_project
android_projectAdit Ghosh
 
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxNgLQun
 
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)eMan s.r.o.
 
Android Things, from mobile apps to physical world
Android Things, from mobile apps to physical worldAndroid Things, from mobile apps to physical world
Android Things, from mobile apps to physical worldStefano Sanna
 

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

Android tips and tricks
Android tips and tricksAndroid tips and tricks
Android tips and tricks
 
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NCAndroid Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
 
Porting and Maintaining your C++ Game on Android without losing your mind
Porting and Maintaining your C++ Game on Android without losing your mindPorting and Maintaining your C++ Game on Android without losing your mind
Porting and Maintaining your C++ Game on Android without losing your mind
 
Developing AIR for Mobile with Flash Professional CS5.5
Developing AIR for Mobile with Flash Professional CS5.5Developing AIR for Mobile with Flash Professional CS5.5
Developing AIR for Mobile with Flash Professional CS5.5
 
Introduction to Android - Mobile Portland
Introduction to Android - Mobile PortlandIntroduction to Android - Mobile Portland
Introduction to Android - Mobile Portland
 
Getting Started with Android - OSSPAC 2009
Getting Started with Android - OSSPAC 2009Getting Started with Android - OSSPAC 2009
Getting Started with Android - OSSPAC 2009
 
Using Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate ReptiliansUsing Android Things to Detect & Exterminate Reptilians
Using Android Things to Detect & Exterminate Reptilians
 
Introduction to Cloud Computing with Google Cloud
Introduction to Cloud Computing with Google CloudIntroduction to Cloud Computing with Google Cloud
Introduction to Cloud Computing with Google Cloud
 
Node in Production at Aviary
Node in Production at AviaryNode in Production at Aviary
Node in Production at Aviary
 
@Ionic native/google-maps
@Ionic native/google-maps@Ionic native/google-maps
@Ionic native/google-maps
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)
 
Non Conventional Android Programming En
Non Conventional Android Programming EnNon Conventional Android Programming En
Non Conventional Android Programming En
 
JS digest. February 2017
JS digest. February 2017JS digest. February 2017
JS digest. February 2017
 
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
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 - Stefano Sanna - Giovanni...Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
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 Things, from mobile apps to physical world by Giovanni Di Gialluca an...Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
 
android_project
android_projectandroid_project
android_project
 
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
 
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
 
Android Things, from mobile apps to physical world
Android Things, from mobile apps to physical worldAndroid Things, from mobile apps to physical world
Android Things, from mobile apps to physical world
 

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

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n