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" and Roid:cleartaskonlaunch= "true" android:taskaffinity= "Android.task.camera" > <intent-filter> & Lt;action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.DEFAU" LT "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-filter> &l t;intent-filter> <action android:name= "Android.media.action.IMAGE_CAPTURE"/> <category D:name= "Android.intent.category.DEFAULT"/> </intent-filter> <intent-filter> <action Android:name= "Android.media.action.STILL_IMAGE_CAMERA"/> <category android:name= "Android.intent.category.d" Efault "/> </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);
}
}
Origin: http://www.cnblogs.com/wuyudong/