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

1,042 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,042
On SlideShare
0
From Embeds
0
Number of Embeds
30
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Google maps and GPS, camera, SD card, tips & tricks

    1. 1. Google maps + GPS,camera, SD cardNikola KapraljevićInfinum Ltd.
    2. 2. About metwitter@nixanikola.kapraljevic@gmail.comAndroidRuby on RailsiPhone
    3. 3. About Infinum Ltd.www.infinumdigital.comMobile and web development company10 peopleOffices in Ljubljana and Zagreb
    4. 4. Google Maps API + GPS
    5. 5. Google APIs Add-Onbe careful when testingexamples you’ll needemulator with “GoogleAPIs”maps don’t workoffline
    6. 6. New project ...Google APIs not Android x.x
    7. 7. Maps API keyregister for Maps API keyhttp://code.google.com/android/maps-api-signup.htmlnixa-macbook:~ nixa$ keytool -list -keystore .android/debug.keystoreEnter keystore password: androidYour keystore contains 1 entryCertificate fingerprint (MD5): 43:9D:9B:48:83:27:69:02:21:61:78:A7:F5:01:7D:F7
    8. 8. Maps API keyplace api key in something like prefs.xmlproduction/development keys are different
    9. 9. AndroidManifest.xml
    10. 10. MapActivity
    11. 11. main.xmlandroid:clickable=”true”
    12. 12. Controlling MapViewshows mapMapController controls the mapMapController controller = map.getController()controller.setZoom(10)controller.setCenter(GeoPoint gp)controller.animateTo(GeoPoint gp)
    13. 13. MyLocationOverlaymyLocationOverlay = new MyLocationOverlay(this,map);myLocationOverlay.runOnFirstFix(Runnable r)myLocationOverlay.enableMyLocation()myLocationOverlay.disableMyLocation()
    14. 14. CustomLocationOverlayextend MyLocationOverlay for custom POI icon
    15. 15. POIs on MapViewMyPOIOverlay extends ItemizedOverlay<OverlayItem>similar to ArrayAdapteroverride protected OverlayItem createItem(int i) public int size()boundCenterBottom(Drawable)keep local copy of data in overlay in case you need to showsome info for POI
    16. 16. MapViewBallonshttps://github.com/jgilfelt/android-mapviewballoons
    17. 17. GPS ...and why I hate GPS
    18. 18. PermissionsFirst you’ll need permissions INTERNET ACCESS_FINE_LOCATION ACCESS_COARSE_LOCATIONSometimes users complain about FINE_LOCATION.Use only if you really need it.
    19. 19. LocationManagerContext.getSystemService(Context.LOCATION_SERVICE)GPS_PROVIDERNETWORK_PROVIDER (cell tower and Wi-Fi basedlocation)locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, time, distance,locationListener);
    20. 20. LocationListener void onLocationChanged(Location location) void onProviderDisabled(String provider) void onProviderEnabled(String provider) void onStatusChanged(String provider, int status, Bundle extras)
    21. 21. GPS testingEmulator telnet localhost 555x geo fix 45.0 22.0Device My Fake Location com.my.fake.location Applications -> Development -> Allow mock locations
    22. 22. GPS more infohttp://developer.android.com/guide/topics/location/obtaining-user-location.htmlhttp://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location-in-a/3145655#3145655we use this in most of our applications
    23. 23. Camera
    24. 24. Permissions<uses-permissionandroid:name="android.permission.CAMERA" /> <uses-featureandroid:name="android.hardware.camera" /> <uses-featureandroid:name="android.hardware.camera.autofocus"android:required="false" />
    25. 25. 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");
    26. 26. Camera via SurfaceHolderfor creating camera applications etc...in 99% cases you don’t need thishttp://developer.android.com/reference/android/hardware/Camera.html
    27. 27. Cropdoesn’t work on all devices!
    28. 28. Cropintent.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");
    29. 29. SD card
    30. 30. SD card<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />Include an empty file named .nomedia in your externalfiles directory (note the dot prefix in the filename). Thiswill prevent Androids media scanner from reading yourmedia files and including them in apps like Gallery orMusic.
    31. 31. SD cardCheck for presence and availability before using SD String state = Environment.getExternalStorageState(); MEDIA_MOUNTED MEDIA_MOUNTED_READ_ONLY
    32. 32. 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
    33. 33. App 2 SDcard<manifest xmlns:android="http://schemas.android.com/apk/res/android"android:installLocation="preferExternal" ... >use location “auto”
    34. 34. Tips & tricks
    35. 35. Droidscreenhttps://github.com/ribomation/DroidAtScreen1
    36. 36. Emulator sucks.
    37. 37. Google Analytics also suck.Use Flurry.
    38. 38. Use version control.
    39. 39. Once again, use versioncontrol!
    40. 40. Use drawable selectors.different images for normal and pressed state
    41. 41. Test on crapy devices.
    42. 42. Threads are you friends.runOnUiThread, Handler
    43. 43. Check out Fragments.They’re cool!
    44. 44. SDK/tools/layoutopt
    45. 45. Standardise your res/*naming convention
    46. 46. Designing app for landscapemode is 2x the work.
    47. 47. Use Dev ToolsICS devices
    48. 48. coloredlogcat.pyhttp://jsharkey.org/blog/2009/04/22/modifying-the-android-logcat-stream-for-full-color-debugging/
    49. 49. Pitanja ...

    ×