标签:
1、照相机代码:
1 package com.example.paizhao; 2 3 import java.io.File; 4 5 import android.net.Uri; 6 import android.os.Bundle; 7 import android.provider.MediaStore; 8 import android.app.Activity; 9 import android.content.Intent; 10 import android.view.Menu; 11 import android.view.View; 12 13 public class MainActivity extends Activity { 14 15 @Override 16 protected void onCreate(Bundle savedInstanceState) { 17 super.onCreate(savedInstanceState); 18 setContentView(R.layout.activity_main); 19 } 20 21 22 public void pai(View view){ 23 Intent intent = new Intent(); 24 intent.setAction("android.media.action.IMAGE_CAPTURE"); 25 intent.addCategory("android.intent.category.DEFAULT"); 26 //说明拍摄的照片放在哪里,并且指定了文件名 27 File file = new File("/sdcard/myimage.jpg"); 28 Uri uri = Uri.fromFile(file); 29 intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); 30 31 startActivity(intent); 32 } 33 34 }
2、录像机代码:
1 package com.example.paizhao; 2 3 import java.io.File; 4 5 import android.net.Uri; 6 import android.os.Bundle; 7 import android.provider.MediaStore; 8 import android.app.Activity; 9 import android.content.Intent; 10 import android.view.Menu; 11 import android.view.View; 12 13 public class MainActivity extends Activity { 14 15 @Override 16 protected void onCreate(Bundle savedInstanceState) { 17 super.onCreate(savedInstanceState); 18 setContentView(R.layout.activity_main); 19 } 20 21 22 public void pai(View view){ 23 Intent intent = new Intent(); 24 intent.setAction("android.media.action.VIDEO_CAPTURE"); 25 intent.addCategory("android.intent.category.DEFAULT"); 26 File file = new File("/sdcard/myvideo.3gp"); 27 Uri uri = Uri.fromFile(file); 28 intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); 29 startActivityForResult(intent, 0); 30 } 31 32 33 @Override 34 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 35 // TODO Auto-generated method stub 36 super.onActivityResult(requestCode, resultCode, data); 37 } 38 39 40 41 }
标签:
原文地址:http://www.cnblogs.com/zhongyinghe/p/5359879.html