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