Android Beginner tutorial calls phone camera and camera function

Source: Internet
Author: User

This small case is recommended to run on the phone.

Package Com.example.camera;import Java.io.file;import Android.net.uri;import android.os.bundle;import Android.os.environment;import Android.provider.mediastore;import Android.app.activity;import Android.content.intent;import Android.view.menu;import Android.view.view;import Android.widget.Toast;public class Mainactivity extends Activity {@Override protected void onCreate (Bundle savedinstancestate) {super.oncreate        (savedinstancestate);    Setcontentview (R.layout.activity_main);    public void image (View v) {Intent Intent = new Intent (); Intent.setaction (mediastore.action_image_capture);//View Google API follow its steps to go Intent.putextra (mediastore.extra_output, Uri.fromfile (New File (Environment.getexternalstoragedirectory (), "haha.jpg")));//Set Save path Startactivityforresult ( Intent, 10);//start system capture function and return value} @Override protected void Onactivityresult (int requestcode, int resultcode, Inten T data) {//TODO auto-generated Method stub Super.onactivityresult (requesTcode, ResultCode, data);    if (requestcode==10) {Toast.maketext (this, "photo successful", 0). Show ();    }if (requestcode==20) {Toast.maketext (this, "camera success", 0). Show ();    }} public void video (View v) {Intent Intent = new Intent ();    Intent.setaction (mediastore.action_video_capture); Intent.putextra (Mediastore.extra_output, Uri.fromfile (New File (Environment.getexternalstoragedirectory (), "    HAHA.3GP ")));    Intent.putextra (mediastore.extra_video_quality, 1);//Set the video quality Startactivityforresult (intent, 20); }}


Android Beginner tutorial calls phone camera and camera function

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.