SlideShare a Scribd company logo
Developing in Android What to do after you have the SDK installed
Outline Creating a new project XML/pragmatically constructing layouts   Initializing the UI  (listeners, ect) Permissions Calling other activities Overview of other functionality  (bluetooth, maps, Camera, ect, preferances) Additional Resources  (google is your best friend) Workshop
Creating a project file->new->project->android project
Project Creation Fields Project Name This is the Eclipse Project name — the name of the directory that will contain the project files. Application Name This is the human-readable title for your application — the name that will appear on the Android device. Package Name This is the package namespace (following the same rules as for packages in the Java programming language) that you want all your source code to reside under. This also sets the package name under which the stub Activity will be generated. Create Activity This is the name for the class stub that will be generated by the plugin. This will be a subclass of Android's  Activity  class. An Activity is simply a class that can run and do work. It can create a UI if it chooses, but it doesn't need to. As the checkbox suggests, this is optional, but an Activity is almost always used as the basis for an application. Min SDK Version This value specifies the minimum API Level required by your application. 
New Project
Activity Lifecycle onCreate() onRestart() onStart() onResume() onPause() onStop() onDestroy() More in Depth Explanation: http://developer.android.com/guide/topics/fundamentals.html
UI Creation
Location of XML
XML Layout <? xml version = &quot;1.0&quot;  encoding = &quot;utf-8&quot; ?> <RelativeLayout   xmlns:android = &quot;http://schemas.android.com/apk/res/android&quot;      android:layout_width = &quot;fill_parent&quot;      android:layout_height = &quot;fill_parent&quot; >      <TextView          android:id = &quot;@+id/label&quot;          android:layout_width = &quot;fill_parent&quot;          android:layout_height = &quot;wrap_content&quot;          android:text = &quot;Type here:&quot; />      <EditText          android:id = &quot;@+id/entry&quot;          android:layout_width = &quot;fill_parent&quot;          android:layout_height = &quot;wrap_content&quot;          android:background = &quot;@android:drawable/editbox_background&quot;          android:layout_below = &quot;@id/label&quot; />      <Button          android:id = &quot;@+id/ok&quot;          android:layout_width = &quot;wrap_content&quot;          android:layout_height = &quot;wrap_content&quot;          android:layout_below = &quot;@id/entry&quot;          android:layout_alignParentRight = &quot;true&quot;          android:layout_marginLeft = &quot;10dip&quot;          android:text = &quot;OK&quot;   />      <Button          android:layout_width = &quot;wrap_content&quot;          android:layout_height = &quot;wrap_content&quot;          android:layout_toLeftOf = &quot;@id/ok&quot;          android:layout_alignTop = &quot;@id/ok&quot;          android:text = &quot;Cancel&quot;   /> </RelativeLayout>
XML vs Programmatically <Button          android:id = &quot;@+id/ok&quot;          android:layout_width = &quot;wrap_content&quot;          android:layout_height = &quot;wrap_content&quot;          android:layout_below = &quot;@id/entry&quot;          android:layout_alignParentRight = &quot;true&quot;          android:layout_marginLeft = &quot;10dip&quot;          android:text = &quot;OK&quot;   /> //intiate button Button ok= new Button(this); //assign ID for later referance ok.setId(R.id.ok); //sets paramiters, wraps content LayoutParams params = new LayoutParams (ViewGroup.Layout           Params.WRAP_CONTENT,          ViewGroup.LayoutParams.WRAP_CONTENT); //sets position within the layout params.addRule(RelativeLayout.layout_below, R.id.entry ); params.addRule(RelativeLayout.layout_alignParentRight); //sets the left margin params.setMargins(10,0,0,0); //sets the params to the button ok.setLayoutParams(params); //sets the text ok.setText(&quot;OK&quot;); //adds the button as a child layout.addView(ok);
Initializing the UI   public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.view_name);          //add listeners      }
Button Listener Button btnName = (Button) findViewById(R.id.btnId); btnNamet.setOnClickListener(new View.OnClickListener() {      public void onClick(View v) {     //sets what the button dose when clicked             }  });
onTouchListener FrameLayout main = (FrameLayout) findViewById(R.id.main_view);       //set touch listener main.setOnTouchListener(new View.OnTouchListener() {      public boolean onTouch(View v, MotionEvent e) {          //x and y  coordinates          float x = e.getX();          float y = e.getY();                        //MotionEvent.ACTION_DOWN=finger presses down          //MotionEvent.ACTION_UP=finger lifts up          //MotionEvent.ACTION_MOVE=change in postion between UP and DOWN           if(e.getAction()==MotionEvent.ACTION_DOWN){               //do something          }      return true;       } });
Manifest.XML <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;        package=&quot;com.RIT.exersize2&quot;        android:versionCode=&quot;1&quot;        android:versionName=&quot;1.0&quot;>        <uses-permission android:name=&quot;android.permission.CAMERA&quot; />      <application android:icon=&quot;@drawable/icon&quot;               android:label=&quot;@string/app_name&quot;>          <activity android:name=&quot;.exersize2&quot;                    android:label=&quot;@string/app_name&quot;>              <intent-filter>                  <action android:name=&quot;android.intent.action.MAIN&quot; />                  <category android:name=&quot;android.intent.category.LAUNCHER&quot; />              </intent-filter>          </activity>      </application> </manifest> 
Some Common Permissions ACCESS_FINE_LOCATION Allows an application to access fine (e.g., GPS) location ACCESS_NETWORK_STATE Allows applications to access information about networks BATTERY_STATS Allows an application to collect battery statistics BLUETOOTH Allows applications to connect to paired bluetooth devices CALL_PHONE Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed. CAMERA Required to be able to access the camera device. EXPAND_STATUS_BAR Allows an application to expand or collapse the status bar. FLASHLIGHT Allows access to the flashlight INTERNET Allows applications to open network sockets. MODIFY_AUDIO_SETTINGS Allows an application to modify global audio settings REBOOT Required to be able to reboot the device. RECEIVE_SMS Allows an application to monitor incoming SMS messages, to record or perform processing on them. SEND_SMS Allows an application to send SMS messages. SET_ALARM Allows an application to broadcast an Intent to set an alarm for the user. SET_ORIENTATION Allows low-level access to setting the orientation (actually rotation) of the screen. SET_TIME Allows applications to set the system time VIBRATE Allows access to the vibrator WRITE_SMS Allows an application to write SMS messages.
Calling Other Apps Intent intent = new Intent(&quot;classpath&quot;); startActivity(intent);          or: startActivityForResult(scan, 0);   public void onActivityResult(int requestCode, int resultCode, Intent intent) {          if (requestCode == 0) {              if (resultCode == RESULT_OK) {                  //name value pair retrieval                  String contents = intent.getStringExtra(&quot;SCAN_RESULT&quot;);                               } else if (resultCode == RESULT_CANCELED) {                  //fail              }          }      }
Bluetooth Ensure that the devise supports Bluetooth Turn Bluetooth on if not already   Find Device   Query Pared Devices   Discover Device   Connecting to a device is almost identical to connecting via TCP Communication between devices is almost identical to TCP as well Bluetooth Tutorial: http://developer.android.com/guide/topics/wireless/bluetooth.html
Location // Acquire a reference to the system Location Manager  LocationManager locationManager = (LocationManager)         this.getSystemService(Context.LOCATION_SERVICE);     // Define a listener that responds to location updates  LocationListener locationListener = new LocationListener() {        public void onLocationChanged(Location location) {            // Called when a new location is found by the network location provider.                   makeUseOfNewLocation(location);        }       public void onStatusChanged(String provider, int status, Bundle extras) {}        public void onProviderEnabled(String provider) {}        public void onProviderDisabled(String provider) {}    };   //Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,               locationListener);  //for GPS use LocationManager.GPS_PROVIDER Tutorial:  http://developer.android.com/guide/topics/location/obtaining-user-location.html
Using the Camera: Activity package android.cameratest; import java.io.IOException; import android.app.Activity; import android.graphics.PixelFormat; import android.hardware.Camera; import android.os.Bundle; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.Window; import android.view.WindowManager; public class CameraTest extends Activity implements SurfaceHolder.Callback, View.OnClickListener{ Bundle bundle; SurfaceView mSurfaceView; SurfaceHolder mSurfaceHolder; Camera mCamera; boolean mPreviewRunning;      /** Called when the activity is first created. */      @Override      public void onCreate(Bundle savedInstanceState) {       super.onCreate(bundle);       getWindow().setFormat(PixelFormat.TRANSLUCENT);       requestWindowFeature(Window.FEATURE_NO_TITLE);       getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,       WindowManager.LayoutParams.FLAG_FULLSCREEN);       setContentView(R.layout.camera_surface);       mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);       mSurfaceView.setOnClickListener((android.view.View.OnClickListener) this);       mSurfaceHolder = mSurfaceView.getHolder();       mSurfaceHolder.addCallback(this);       mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);      }
Using The Camera: Activity /** * When the surface is first created. * Open the camera harware. */ public void surfaceCreated(SurfaceHolder holder) { mCamera = Camera.open(); } /**       * Called when the surface/format of the surface changes. Can be change in orientation or screen off.       * Called after surfaceCreated. Set up camera settings.       */ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { if (mPreviewRunning) { mCamera.stopPreview(); } Camera.Parameters p = mCamera.getParameters(); p.setPreviewSize(width, height); mCamera.setParameters(p); try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { e.printStackTrace(); } mCamera.startPreview(); mPreviewRunning = true; } /** * Called when surface is destroyed.  When screen is black. */ public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mPreviewRunning = false;                  mCamera.release();  }
Using The Camera: Activity /** * The camera callback. Put code that deals with the image returned in byte form. *  */ Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { public void onPictureTaken(byte[] imageData, Camera c) { } /* * What is done with the data (imageData) byte stream.  * Can save it to files or edit it.  */ }; /** * Takes the picture when the screen is touched. * @param v */ public void onClick(View v) { //Call on the camera  hardware to take a picture. mCamera.takePicture(null, mPictureCallback, mPictureCallback); mCamera.startPreview(); mPreviewRunning = true; }      }
     Flow of Taking a Picture
Additional Resources  API:  http://developer.android.com/reference/packages.html Developers guide:  http://developer.android.com/guide/index.html http://stackoverflow.com   is a great place to ask questions When in doubt, Google knows all
Workshop Implement an application which reads a URL from a QR code and then opens the page in a browser.
API:  http://developer.android.com/reference/packages.html Barcode Reader: http://code.google.com/p/zxing/ Normal Project: http://people.rit.edu/cld8812/Exersize2.zip Easy Project: http://people.rit.edu/cld8812/Exersize2Easy.zip
Thanks for Coming! The completed workshop can be found at: http://people.rit.edu/cld8812/ExersizeFinal.zip

More Related Content

What's hot (16)

PPTX
Intro to appcelerator
Mohab El-Shishtawy
 
PPT
Processing XML with Java
BG Java EE Course
 
PDF
Introduction to Titanium and how to connect with a PHP backend
Joseluis Laso
 
KEY
Android workshop
Nikola Kapraljevic Nixa
 
PPTX
Java applet - java
Rubaya Mim
 
PPT
first-applet
Mohit Patodia
 
PDF
Capture image on eye blink
InnovationM
 
PDF
Bowtie: Interactive Dashboards
Jacques Kvam
 
DOCX
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
PDF
Desenvolva um game para android ou iPhone
Tiago Oliveira
 
PDF
I have adream
Kathryn Evans
 
ODP
Non Conventional Android Programming En
guest9bcef2f
 
PPTX
Applet
swapnac12
 
PPTX
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
Daniel Fisher
 
PDF
Java applet basics
Sunil Pandey
 
DOCX
Leture5 exercise onactivities
maamir farooq
 
Intro to appcelerator
Mohab El-Shishtawy
 
Processing XML with Java
BG Java EE Course
 
Introduction to Titanium and how to connect with a PHP backend
Joseluis Laso
 
Android workshop
Nikola Kapraljevic Nixa
 
Java applet - java
Rubaya Mim
 
first-applet
Mohit Patodia
 
Capture image on eye blink
InnovationM
 
Bowtie: Interactive Dashboards
Jacques Kvam
 
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
Desenvolva um game para android ou iPhone
Tiago Oliveira
 
I have adream
Kathryn Evans
 
Non Conventional Android Programming En
guest9bcef2f
 
Applet
swapnac12
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
Daniel Fisher
 
Java applet basics
Sunil Pandey
 
Leture5 exercise onactivities
maamir farooq
 

Similar to Developing in android (20)

PPT
21 android2 updated
GhanaGTUG
 
PPTX
Building apps for multiple devices
Terry Ryan
 
ODP
Geekcamp Android
Hean Hong Leong
 
PPT
Migrating JavaME Apps to Android
Motorola Mobility - MOTODEV
 
PPTX
Introduction To Google Android (Ft Rohan Bomle)
Fafadia Tech
 
PPT
Ui patterns
OSCON Byrum
 
PPT
Beautifully Usable, Multiple Screens Too
Motorola Mobility - MOTODEV
 
ODP
Non Conventional Android Programming (English)
Davide Cerbo
 
PPT
Introduction to Android Fragments
Sergi Martínez
 
PPTX
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Jim Tochterman
 
PDF
Advanced Android gReporter
natdefreitas
 
PDF
android level 3
DevMix
 
ODP
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
PDF
Android Intro
Justin Grammens
 
PDF
Android TCJUG
Justin Grammens
 
PPT
Android the Agile way
Ashwin Raghav
 
PPT
Creating Yahoo Mobile Widgets
Ricardo Varela
 
KEY
Android Workshop
Junda Ong
 
ODP
Interoperable Web Services with JAX-WS
Carol McDonald
 
PPT
Intro to Android Programming
Peter van der Linden
 
21 android2 updated
GhanaGTUG
 
Building apps for multiple devices
Terry Ryan
 
Geekcamp Android
Hean Hong Leong
 
Migrating JavaME Apps to Android
Motorola Mobility - MOTODEV
 
Introduction To Google Android (Ft Rohan Bomle)
Fafadia Tech
 
Ui patterns
OSCON Byrum
 
Beautifully Usable, Multiple Screens Too
Motorola Mobility - MOTODEV
 
Non Conventional Android Programming (English)
Davide Cerbo
 
Introduction to Android Fragments
Sergi Martínez
 
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Jim Tochterman
 
Advanced Android gReporter
natdefreitas
 
android level 3
DevMix
 
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
Android Intro
Justin Grammens
 
Android TCJUG
Justin Grammens
 
Android the Agile way
Ashwin Raghav
 
Creating Yahoo Mobile Widgets
Ricardo Varela
 
Android Workshop
Junda Ong
 
Interoperable Web Services with JAX-WS
Carol McDonald
 
Intro to Android Programming
Peter van der Linden
 
Ad

Developing in android

  • 1. Developing in Android What to do after you have the SDK installed
  • 2. Outline Creating a new project XML/pragmatically constructing layouts   Initializing the UI (listeners, ect) Permissions Calling other activities Overview of other functionality (bluetooth, maps, Camera, ect, preferances) Additional Resources (google is your best friend) Workshop
  • 3. Creating a project file->new->project->android project
  • 4. Project Creation Fields Project Name This is the Eclipse Project name — the name of the directory that will contain the project files. Application Name This is the human-readable title for your application — the name that will appear on the Android device. Package Name This is the package namespace (following the same rules as for packages in the Java programming language) that you want all your source code to reside under. This also sets the package name under which the stub Activity will be generated. Create Activity This is the name for the class stub that will be generated by the plugin. This will be a subclass of Android's  Activity  class. An Activity is simply a class that can run and do work. It can create a UI if it chooses, but it doesn't need to. As the checkbox suggests, this is optional, but an Activity is almost always used as the basis for an application. Min SDK Version This value specifies the minimum API Level required by your application. 
  • 6. Activity Lifecycle onCreate() onRestart() onStart() onResume() onPause() onStop() onDestroy() More in Depth Explanation: http://developer.android.com/guide/topics/fundamentals.html
  • 9. XML Layout <? xml version = &quot;1.0&quot; encoding = &quot;utf-8&quot; ?> <RelativeLayout xmlns:android = &quot;http://schemas.android.com/apk/res/android&quot;     android:layout_width = &quot;fill_parent&quot;     android:layout_height = &quot;fill_parent&quot; >     <TextView         android:id = &quot;@+id/label&quot;         android:layout_width = &quot;fill_parent&quot;         android:layout_height = &quot;wrap_content&quot;         android:text = &quot;Type here:&quot; />     <EditText         android:id = &quot;@+id/entry&quot;         android:layout_width = &quot;fill_parent&quot;         android:layout_height = &quot;wrap_content&quot;         android:background = &quot;@android:drawable/editbox_background&quot;         android:layout_below = &quot;@id/label&quot; />     <Button         android:id = &quot;@+id/ok&quot;         android:layout_width = &quot;wrap_content&quot;         android:layout_height = &quot;wrap_content&quot;         android:layout_below = &quot;@id/entry&quot;         android:layout_alignParentRight = &quot;true&quot;         android:layout_marginLeft = &quot;10dip&quot;         android:text = &quot;OK&quot; />     <Button         android:layout_width = &quot;wrap_content&quot;         android:layout_height = &quot;wrap_content&quot;         android:layout_toLeftOf = &quot;@id/ok&quot;         android:layout_alignTop = &quot;@id/ok&quot;         android:text = &quot;Cancel&quot; /> </RelativeLayout>
  • 10. XML vs Programmatically <Button         android:id = &quot;@+id/ok&quot;         android:layout_width = &quot;wrap_content&quot;         android:layout_height = &quot;wrap_content&quot;         android:layout_below = &quot;@id/entry&quot;         android:layout_alignParentRight = &quot;true&quot;         android:layout_marginLeft = &quot;10dip&quot;         android:text = &quot;OK&quot; /> //intiate button Button ok= new Button(this); //assign ID for later referance ok.setId(R.id.ok); //sets paramiters, wraps content LayoutParams params = new LayoutParams (ViewGroup.Layout           Params.WRAP_CONTENT,          ViewGroup.LayoutParams.WRAP_CONTENT); //sets position within the layout params.addRule(RelativeLayout.layout_below, R.id.entry ); params.addRule(RelativeLayout.layout_alignParentRight); //sets the left margin params.setMargins(10,0,0,0); //sets the params to the button ok.setLayoutParams(params); //sets the text ok.setText(&quot;OK&quot;); //adds the button as a child layout.addView(ok);
  • 11. Initializing the UI   public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.view_name);          //add listeners      }
  • 12. Button Listener Button btnName = (Button) findViewById(R.id.btnId); btnNamet.setOnClickListener(new View.OnClickListener() {      public void onClick(View v) {    //sets what the button dose when clicked             }  });
  • 13. onTouchListener FrameLayout main = (FrameLayout) findViewById(R.id.main_view);       //set touch listener main.setOnTouchListener(new View.OnTouchListener() {      public boolean onTouch(View v, MotionEvent e) {          //x and y  coordinates         float x = e.getX();          float y = e.getY();                        //MotionEvent.ACTION_DOWN=finger presses down          //MotionEvent.ACTION_UP=finger lifts up          //MotionEvent.ACTION_MOVE=change in postion between UP and DOWN          if(e.getAction()==MotionEvent.ACTION_DOWN){              //do something          }      return true;       } });
  • 14. Manifest.XML <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;        package=&quot;com.RIT.exersize2&quot;        android:versionCode=&quot;1&quot;        android:versionName=&quot;1.0&quot;>        <uses-permission android:name=&quot;android.permission.CAMERA&quot; />      <application android:icon=&quot;@drawable/icon&quot;               android:label=&quot;@string/app_name&quot;>          <activity android:name=&quot;.exersize2&quot;                    android:label=&quot;@string/app_name&quot;>              <intent-filter>                  <action android:name=&quot;android.intent.action.MAIN&quot; />                  <category android:name=&quot;android.intent.category.LAUNCHER&quot; />              </intent-filter>          </activity>      </application> </manifest> 
  • 15. Some Common Permissions ACCESS_FINE_LOCATION Allows an application to access fine (e.g., GPS) location ACCESS_NETWORK_STATE Allows applications to access information about networks BATTERY_STATS Allows an application to collect battery statistics BLUETOOTH Allows applications to connect to paired bluetooth devices CALL_PHONE Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed. CAMERA Required to be able to access the camera device. EXPAND_STATUS_BAR Allows an application to expand or collapse the status bar. FLASHLIGHT Allows access to the flashlight INTERNET Allows applications to open network sockets. MODIFY_AUDIO_SETTINGS Allows an application to modify global audio settings REBOOT Required to be able to reboot the device. RECEIVE_SMS Allows an application to monitor incoming SMS messages, to record or perform processing on them. SEND_SMS Allows an application to send SMS messages. SET_ALARM Allows an application to broadcast an Intent to set an alarm for the user. SET_ORIENTATION Allows low-level access to setting the orientation (actually rotation) of the screen. SET_TIME Allows applications to set the system time VIBRATE Allows access to the vibrator WRITE_SMS Allows an application to write SMS messages.
  • 16. Calling Other Apps Intent intent = new Intent(&quot;classpath&quot;); startActivity(intent);          or: startActivityForResult(scan, 0);   public void onActivityResult(int requestCode, int resultCode, Intent intent) {          if (requestCode == 0) {              if (resultCode == RESULT_OK) {                  //name value pair retrieval                  String contents = intent.getStringExtra(&quot;SCAN_RESULT&quot;);                               } else if (resultCode == RESULT_CANCELED) {                  //fail              }          }      }
  • 17. Bluetooth Ensure that the devise supports Bluetooth Turn Bluetooth on if not already   Find Device   Query Pared Devices   Discover Device   Connecting to a device is almost identical to connecting via TCP Communication between devices is almost identical to TCP as well Bluetooth Tutorial: http://developer.android.com/guide/topics/wireless/bluetooth.html
  • 18. Location // Acquire a reference to the system Location Manager  LocationManager locationManager = (LocationManager)         this.getSystemService(Context.LOCATION_SERVICE);     // Define a listener that responds to location updates  LocationListener locationListener = new LocationListener() {        public void onLocationChanged(Location location) {            // Called when a new location is found by the network location provider.                   makeUseOfNewLocation(location);        }       public void onStatusChanged(String provider, int status, Bundle extras) {}        public void onProviderEnabled(String provider) {}        public void onProviderDisabled(String provider) {}    };   //Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,               locationListener);  //for GPS use LocationManager.GPS_PROVIDER Tutorial:  http://developer.android.com/guide/topics/location/obtaining-user-location.html
  • 19. Using the Camera: Activity package android.cameratest; import java.io.IOException; import android.app.Activity; import android.graphics.PixelFormat; import android.hardware.Camera; import android.os.Bundle; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.Window; import android.view.WindowManager; public class CameraTest extends Activity implements SurfaceHolder.Callback, View.OnClickListener{ Bundle bundle; SurfaceView mSurfaceView; SurfaceHolder mSurfaceHolder; Camera mCamera; boolean mPreviewRunning;      /** Called when the activity is first created. */      @Override      public void onCreate(Bundle savedInstanceState) {      super.onCreate(bundle);      getWindow().setFormat(PixelFormat.TRANSLUCENT);      requestWindowFeature(Window.FEATURE_NO_TITLE);      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,      WindowManager.LayoutParams.FLAG_FULLSCREEN);      setContentView(R.layout.camera_surface);      mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);      mSurfaceView.setOnClickListener((android.view.View.OnClickListener) this);      mSurfaceHolder = mSurfaceView.getHolder();      mSurfaceHolder.addCallback(this);      mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);      }
  • 20. Using The Camera: Activity /** * When the surface is first created. * Open the camera harware. */ public void surfaceCreated(SurfaceHolder holder) { mCamera = Camera.open(); } /**      * Called when the surface/format of the surface changes. Can be change in orientation or screen off.      * Called after surfaceCreated. Set up camera settings.      */ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { if (mPreviewRunning) { mCamera.stopPreview(); } Camera.Parameters p = mCamera.getParameters(); p.setPreviewSize(width, height); mCamera.setParameters(p); try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { e.printStackTrace(); } mCamera.startPreview(); mPreviewRunning = true; } /** * Called when surface is destroyed.  When screen is black. */ public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mPreviewRunning = false;                  mCamera.release(); }
  • 21. Using The Camera: Activity /** * The camera callback. Put code that deals with the image returned in byte form. *  */ Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { public void onPictureTaken(byte[] imageData, Camera c) { } /* * What is done with the data (imageData) byte stream.  * Can save it to files or edit it.  */ }; /** * Takes the picture when the screen is touched. * @param v */ public void onClick(View v) { //Call on the camera  hardware to take a picture. mCamera.takePicture(null, mPictureCallback, mPictureCallback); mCamera.startPreview(); mPreviewRunning = true; }     }
  • 22.      Flow of Taking a Picture
  • 23. Additional Resources  API:  http://developer.android.com/reference/packages.html Developers guide:  http://developer.android.com/guide/index.html http://stackoverflow.com   is a great place to ask questions When in doubt, Google knows all
  • 24. Workshop Implement an application which reads a URL from a QR code and then opens the page in a browser.
  • 25. API:  http://developer.android.com/reference/packages.html Barcode Reader: http://code.google.com/p/zxing/ Normal Project: http://people.rit.edu/cld8812/Exersize2.zip Easy Project: http://people.rit.edu/cld8812/Exersize2Easy.zip
  • 26. Thanks for Coming! The completed workshop can be found at: http://people.rit.edu/cld8812/ExersizeFinal.zip