Android Call system camera photo and video _android

Source: Internet
Author: User

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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.