This article implements the Android system camera call to take photos
The layout of the project is fairly simple, with only one button:
<relativelayout xmlns: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 ">
<button
android: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 Photo"/>
</RelativeLayout>
First open the list file under the Packages\apps\camera folder and find the following code:
<activity android:name= "Com.android.camera.Camera" android:configchanges= "Orientation|keyboardhidden" Android:theme= "@android: Style/theme.black.notitlebar.fullscreen" android:screenorientation= "Landscape" an
Droid:cleartaskonlaunch= "true" android:taskaffinity= "Android.task.camera" > <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.DEFA" ULT "/> <category android:name= Android.intent.category.LAUNCHER"/> </intent-filter> & lt;intent-filter> <action android:name= "Android.media.action.IMAGE_CAPTURE"/> <category Id:name= "Android.intent.category.DEFAULT"/> </intent-filter> <intent-filter> <actio n android:name= "Android.media.action.STILL_IMAGE_CAMERA"/> <category android:name= "Android.intent.category". DEFAULT "/>;/intent-filter> </activity>
The relevant code is as follows:
public class Mainactivity extends activity {
@Override
protected void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
}
public void Click (View view) {
*
* * <intent-filter> <action
* android:name= Android.media.action.IMAGE_CAPTURE "/> <category
* android:name=" Android.intent.category.DEFAULT "/> </intent-filter>//
Activate the camera for the system to take photos
intent intent = new intent ();
Intent.setaction ("Android.media.action.IMAGE_CAPTURE");
Intent.addcategory ("Android.intent.category.DEFAULT");
Saves the photo to the specified path
file = new file ("/sdcard/image.jpg");
Uri uri = uri.fromfile (file);
Intent.putextra (Mediastore.extra_output, URI);
StartActivity (intent);
}
The relevant code to activate the video function is also simple:
public class Mainactivity extends activity {@Override protected void onCreate (Bundle savedinstancestate) {Supe
R.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main); public void Click (View view) {/* <intent-filter> <action * android:name=) android.media.acti On.
Video_capture "/> <category * android:name=" Android.intent.category.DEFAULT "/> </intent-filter>
*///Activate the camera of the system for video Intent Intent = new Intent ();
Intent.setaction ("Android.media.action.VIDEO_CAPTURE");
Intent.addcategory ("Android.intent.category.DEFAULT");
Save the video to the specified path file = new file ("/sdcard/video.3pg");
Uri uri = uri.fromfile (file);
Intent.putextra (Mediastore.extra_output, URI);
Startactivityforresult (Intent, 0); @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {Toast.maketext (this
, "Call camera Complete", 0. Show (); Super.onactivityresult (Requestcode, ResultCode, data);
}
}
Thank you for reading, I hope to help you, thank you for your support for this site!