1 / 48

Google Maps API

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:

kisha
Télécharger la présentation

Google Maps API

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Google Maps API

  2. Google Maps on Android • A nice API for mapping applications

  3. 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

  4. 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

  5. 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

  6. Using the Map Controller • Using the Map is easy… • MapControllermyMC = myMapView.getController(); • myMC.setZoom(17); // set the zoom level • myMapView.setSatellite(); // sets sat view

  7. 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

  8. Intents

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

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

  11. Launch another Activity Intent intent = new Intent(FirstActivity.this, AnotherActivity.class); startActivity(intent); This will launch another activity (screen) without destroying the first

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

  13. Launch Google Maps String uri = “geo:37.523156,-121.084917” Intent myIntent= New Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)); startActivity(myIntent);

  14. 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

  15. Android Intent Docs • http://developer.android.com/guide/topics/intents/intents-filters.html

  16. Files and Storage on Android Devices

  17. Storage • Four basic ways • Shared Preferences • Database • Files on the Device • The “cloud” • http://developer.android.com/guide/topics/data/data-storage.html

  18. Shared Preferences • Easy, built in way to save preferences to the device • App settings, • Similar to the Windows registry • SharedPreferences class in the API

  19. SharedPreferences Example • SharedPreferences settings = getSharedPreferences(PREFS_NAME, default_value); • boolean value = settings.getBoolean(“prefName", default_value);

  20. Database • Local database on the device • SQLite • For heavier-duty data requirements / queries db.execSQL(“SELECT * …”);

  21. Files • Can store data to a file • Useful for saving media files, save games, etc. • Just like writing files in Java FileOutputStreamfos = openFileOutput(FILENAME, Context.MODE_PRIVATE); fos.write(string.getBytes()); fos.close();

  22. 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

  23. Amazon AWS • Allows you to save data to Amazon servers • An API for Android • http://aws.amazon.com/

  24. 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

  25. Broadcast Receivers

  26. Broadcast Receivers • These allow you to ‘intercept’ messages • That you create, or… • That the system sends

  27. 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

  28. 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

  29. Then… • Just fill in the onReceive() method. • This is the code that “handles” the event

  30. Some System Intents • ACTION_TIME_TICK • A minute has passed • ACTION_BATTERY_LOW • Need to plug it in! • SMS_RECEIVED • You got a text!

  31. Android BR Docs • http://developer.android.com/reference/android/content/BroadcastReceiver.html

  32. Android Databases

  33. Databases • Android uses the SQLite Database • A lightweight database server • Returns the Android ‘Cursor’ instead of rows – for efficiency.

  34. 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

  35. SQLiteOpenHelper • Your helper class can also extend the SQLiteOpenHelper abstract class • To simplify creating and opening databases

  36. Cursors • Instead of returning rows, you get a Cursor to manage the results of a query • Cursor myResult = myDB.query (…); • myResult.getString(columnIndex);

  37. Notepad Tutorial • Great tutorial for database concepts • Includes: • Integrating the ListView with a DB -> • http://developer.android.com/resources/tutorials/notepad/index.html

  38. Publishing Your Apps

  39. Signing • This is required to release your application • Several Steps… • The tutorial • http://developer.android.com/guide/publishing/app-signing.html

  40. 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

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

  42. Device • Make sure your device allows apps that are not from the app store • In configuration menu

  43. 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!

  44. Simulator • Test on all available AVD versions • Specify the <uses-sdk> parameter in the manifest, and test on all devices after that version

  45. Simulator • In Eclipse’s Run->Run Configuration • Specify Network speed and latency to test under varying conditions • Test on a real device also

  46. 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

  47. 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

  48. Proguard Documentation • http://developer.android.com/guide/developing/tools/proguard.html • Shrinks, optimizes, and obfuscates the code

More Related