android camera example
TRANSCRIPT
-
8/19/2019 Android Camera Example
1/11
Android Camera
Example
-
8/19/2019 Android Camera Example
2/11
Intents:An Intent is exactly what it describes. It's an
"intention" to do an action.
An Intent is basically a message to say youdid or want something to happen. Dependingon the intent, apps or the OS might belistening or it and will react accordingly.
Intents can be used to signal to the Androidsystem that a certain eent has occurred.Other components in Android can register tothis eent ia an intent #lter.
-
8/19/2019 Android Camera Example
3/11
$aniest Declarations%eore starting deelopment on your
application with the &amera , you shouldmae sure your maniest has the appropriatedeclarations to allow use o camera hardwareand other related eatures.
(uses)permissionandroid:name*"android.permission.&A$+A" -
(uses)eature
android:name*"android.hardware.camera" -(uses)permission
android:name*"android.permission./I0+1+20+3A41S0OA5+" -
-
8/19/2019 Android Camera Example
4/11
ACTION_IMAGE_CAPTUREStandard Intent action that can be sent to
hae the camera application capture an imageand return it.
-
8/19/2019 Android Camera Example
5/11
+xample:
(6xml ersion*"7.8" encoding*"ut)9"6
(maniest xmlns:android*"http:--schemas.android.com-ap-res-android"
pacage*"grewe.example.&amera.Simple"
android:ersion&ode*"7"
android:ersion3ame*"7.8"
(uses)sd android:minSdersion*"7;" -
(application android:icon*"+" -
(-intent)#lter
(-actiity
(-application
(-maniest
-
8/19/2019 Android Camera Example
6/11
import android.os.+undle,
import android.iew.Menu,
import android.iew.Menutem,
import android.iew.iew,
import android.widet.#extiew,import android.annotation.(uppress'int,
import android.ontent.ntent,
import android.proider.Media(tore,
import android.widet.#oast,
import android.net.0ri,
import 1aa.io.2ile,import android.os.Enironment,
import android.app.Atiit3,
import android.widet.maeiew,
import android.raphis.+itmap,
public class Camera(impleAtiit3 extends Atiit3 ?
-
8/19/2019 Android Camera Example
7/11
priate stati 4nal int ACTIVITY_START_CAMERA_APP=0;
priate maeiew mphotoaptureimaeiew,
-
8/19/2019 Android Camera Example
8/11
andle action bar item clics here. 0he action bar will -- automatically handle clics on the >ome-=p button, so
long
-- as you speciy a parent actiity in Android$aniest.xml.
int id = item.ettemd56,
if 5id == R.id.action_settings) { return true,
B
return super.on)ptionstem(eleted5item6,
B
-
8/19/2019 Android Camera Example
9/11
pu8li oid photo5iew iew6
?
Intent icamera* new ntent56,
icamera.setAction@$ediaStore. ACTION_IMAGE_CAPTURE);
startActiityEoresult@icamera, ACTIVITY_TART_CAMERA _APP );
B
-
8/19/2019 Android Camera Example
10/11
proteted oid )nAtiit3Result5int re9uestCodeintresultCodentent data6
?
if5re9uestCode== ACTIVITY_START_CAMERA_APP &&
resultCoe==RES!"T_#$) ?
--0oast.mae0ext@this,"it wors",0oast.4+350>1S>O0.show@
%undle extras*data.get+xtras@
%itmap photocapturebitmap* @%itmap extras .get@"data"
mphotocaptureimageiew.setImage%itmap@photocapturebitmap B
B
B
-
8/19/2019 Android Camera Example
11/11