This article implements the call of the Android system camera to take pictures
The layout of the project is fairly simple, with only one button:
<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context=". Mainactivity " > <ButtonAndroid:onclick= "click"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_centerhorizontal= "true"android:layout_centervertical= "true"Android:text= "Call system camera to take pictures" /></Relativelayout>
First open the manifest file under the Packages\apps\camera folder and locate the following code:
<ActivityAndroid:name= "Com.android.camera.Camera"android:configchanges= "Orientation|keyboardhidden"Android:theme= "@android: Style/theme.black.notitlebar.fullscreen"android:screenorientation= "Landscape"Android:cleartaskonlaunch= "true"android:taskaffinity= "Android.task.camera"> <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> <intent-filter><action android:name= " Android.media.action.IMAGE_CAPTURE " /><category android:name = "Android.intent.category.DEFAULT" /> </ Intent-filter > <Intent-filter> <ActionAndroid:name= "Android.media.action.STILL_IMAGE_CAMERA" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> </Intent-filter> </Activity>
The relevant code is as follows:
Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); } Public voidClick (View view) {/** <intent-filter> <action * android:name= "Android.media.action.IMAGE_CAPTURE"/> <cate Gory * android:name= "Android.intent.category.DEFAULT"/> </intent-filter>*/ //activating the system's camera for taking picturesIntent Intent =NewIntent (); Intent.setaction ("Android.media.action.IMAGE_CAPTURE"); Intent.addcategory ("Android.intent.category.DEFAULT"); //save a photo to a specified pathFile File =NewFile ("/sdcard/image.jpg"); Uri URI=uri.fromfile (file); Intent.putextra (Mediastore.extra_output, URI); StartActivity (Intent); }}
It is also easy to implement the relevant code for activating the recording function:
Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); } Public voidClick (View view) {/** <intent-filter> <action * android:name= "Android.media.action.VIDEO_CAPTURE"/> <cate Gory * android:name= "Android.intent.category.DEFAULT"/> </intent-filter>*/ //activating the system's camera for recordingIntent Intent =NewIntent (); Intent.setaction ("Android.media.action.VIDEO_CAPTURE"); Intent.addcategory ("Android.intent.category.DEFAULT"); //Save the recording to the specified pathFile File =NewFile ("/sdcard/video.3pg"); Uri URI=uri.fromfile (file); Intent.putextra (Mediastore.extra_output, URI); Startactivityforresult (Intent,0); } @Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {Toast.maketext ( This, "Call camera complete", 0). Show (); Super. Onactivityresult (Requestcode, ResultCode, data); }}
Android calls system camera to take pictures and videos