Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1077812
  • 博文数量: 403
  • 博客积分: 10272
  • 博客等级: 上将
  • 技术积分: 4407
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 14:22
文章分类

全部博文(403)

文章存档

2012年(403)

分类: 嵌入式

2012-04-26 21:16:09

 

复制代码
public class MyCameraActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btnCamera = (Button) findViewById(R.id.btnCamera); btnCamera.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub letCamera(); } }); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case 1:// 拍照 if (resultCode == RESULT_OK) { Toast.makeText(this, "拍摄成功", Toast.LENGTH_SHORT).show(); } break; default: break; } } protected void letCamera() { // TODO Auto-generated method stub Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); String strImgPath = Environment.getExternalStorageDirectory() .toString() + "/dlion/";// 存放照片的文件夹 String fileName = new SimpleDateFormat("yyyyMMddHHmmss") .format(new Date()) + ".jpg";// 照片命名 File out = new File(strImgPath); if (!out.exists()) { out.mkdirs(); } out = new File(strImgPath, fileName); strImgPath = strImgPath + fileName;// 该照片的绝对路径 Uri uri = Uri.fromFile(out); imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); imageCaptureIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); startActivityForResult(imageCaptureIntent, 1); } }
复制代码
阅读(2188) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~