Upcoming SlideShare
Loading in...5







Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Notes Notes Presentation Transcript

  • Comp194-MA
  • Introduction
    • Android includes a rich widget toolkit.
    • Cool ones: a Google Map, MediaPlayer, Photo Gallery, ect
    • The best way to figure out the widgets is to experiment with them.
    • These slides will walk through the GeoFlickr app.
  • GeoFlickr
    • GeoFlickr retrieves the user’s current GPS coordinates and pulls flickr photos around that location.
    • The app uses Android’s Gallery widget to display the retrieved photos.
    • It also uses Android threads and handlers so the UI doesn’t freeze
  • Screenshots Home screen Loading Screen
  • Screenshots Photos outside MFA “ onclick” behavior
  • Juicy bits
    • GeoFlickr uses Android threads as well as the LocationManager service to determine GPS coordinates.
    • We’ll walk through how to set up LocationManager and throw out some snippets for threading.
  • Location, Location, Location
    • Location based services are some of the most exciting applications of mobile apps.
    • The Android SDK exposes it’s GPS service through the LocationManager service.
    • Applications can either poll the service for updates or opt to receive updates when the device moves by a certain amount.
  • Setup
    • Before an application can access location service it needs to set up permissions in the AndroidManifest file.
    • The Eclipse plugin provides a GUI to add the appropriate XML tags to the file.
    • Open “AndroidManifest.xml” and select the “Permissions” tab on the bottom.
  • Setup contd.
    • Add the following as “Uses Permission”
    • android.permission.ACCESS_MOCK_LOCATION
    • android.permission.ACCESS_COARSE_LOCATION
    • android.permission.ACCESS_FINE_LOCATION
    • If you want to use sockets add: android.permission.INTERNET
  • Setting up DDMS
    • Since the emulator doesn’t have a physical GPS, the DDMS console allows developer’s to send fake GPS coordinates to the emulator.
    • To bring up DDMS in Eclipse: Window->Open Perspective->Other->DDMS
    • To enable LogCat logging in Eclipse: Window->Preferences->Android->DDMS and change the log level to info.
  • DDMS Send GPS coords Logging System info
  • LocationManager code
    • Register for location updates:
    • LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    • flickrLocationReciever flReciever = new flickrLocationReciever();
    • locationManager. requestLocationUpdates( locationManager.getProviders( true).get(0), 5, 10, flReciever);
    • public class flickrLocationReciever implements LocationListener {
    • @Override
    • public void onLocationChanged(final Location arg0) {
    • // do things
    • }
    • }
  • Gallery Adapters
    • Android’s gallery widget accepts an adapter object to facilitate rendering.
    • Adapter’s are flexible because they allow developer’s to respond to gallery events in a particular fashion.
    • They also allow developer’s to change how gallery items will render.
  • Gallery Code
    • ImageAdapter ia = new ImageAdapter(this);
    • Gallery ga = ((Gallery) findViewById( imageGallery));
    • ga.setAdapter(ia);
    • public class ImageAdapter extends BaseAdapter {
      • // override all the methods and do stuff
    • }
  • Threading
    • Using threads for background tasks is important because it allows the UI to remain responsive.
    • Android implements threads using the standard Java threading model.
    • Events are raised using the “Message” class and handled using the “Handler” class.
  • Threading code
    • Thread t = new Thread() {
    • public void run(){
    • // do stuff
    • // let the handler know we are done
    • handler.sendEmptyMessage(1);
    • }}
    • T.start();
    • private Handler handler = new Handler(){
    • public void handleMessage(Message msg) {
    • // handle the end of the thread
    • }}
  • Playing With Google Maps
    • Android has a built in widget for the maps called MapView
    • MapView requires an API key which is based off something called “keystore”.
    • Since we are running in Debug environment we can use the debug.keystore that android creates us in ~/.andriod/debug.keystore usually
  • Getting your Maps API Key
    • First get your md5 finger print
      • daum@daum ~/.android $ keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android androiddebugkey, Jan 26, 2009, PrivateKeyEntry, Certificate fingerprint (MD5): B8:F5:D9:31:8D:19:C6:13:86:7F:4F:B3:A4:C9:A2:CC
    • Take the B8…….CC to and get your API key
    • When you implement the MapView widget add android:apiKey=“YOUR KEY” to the widget
  • Maps Require the Internet
    • GoogleMaps requires that you have access to the internet so your application needs permission to use the internet
    • Add the permission as a child under “manifest” in AndriodManifest.xml
      • <uses-permission android:name=“android.permission.INTERNET” />
    • Now you should be able to simply load the map
  • Map Troubleshooting
    • If you see the Map but none of the actual tiles are loading on the map there are two possible problems
      • You do not have the correct API key, make sure you are using your debug one (or your production one if you are publishing the app)
      • Your application does not have access to the Internet
    • If you check both of the above problems, you most likely will end with a map that works
  • A map with no tools is no Map at all
    • Now we have a map, but we cannot click on it, zoom in or out on it. To make it clickable you can in the MapView widget in the xml add
      • android:clickable=“true”
    • Now you can click but we still cannot zoom. There is a zoom widget called ZoomControl!
      • Get the ZoomControl from the MapView
        • Mapview.getZoomControls()
      • Add it to the a linear layout at the bottom of the map to make them visible
        • linearLayout.addView(Mapview.getZoomControls()
      • Now we have a function map!