标签:
1 package com.itheima.systemcamera; 2 3 import android.app.Activity; 4 import android.content.Intent; 5 import android.net.Uri; 6 import android.os.Bundle; 7 import android.provider.MediaStore; 8 import android.view.View; 9 import android.widget.Toast; 10 11 public class MainActivity extends Activity { 12 private Uri imageUri = Uri.parse("file:///mnt/sdcard/" + System.currentTimeMillis() + ".jpg"); 13 private Uri videoUri = Uri.parse("file:///mnt/sdcard/" + System.currentTimeMillis() + ".mp4"); 14 15 @Override 16 protected void onCreate(Bundle savedInstanceState) { 17 super.onCreate(savedInstanceState); 18 setContentView(R.layout.activity_main); 19 } 20 21 public void takeImage(View v) { 22 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // 创建意图, 指定动作(拍照) 23 intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); // 指定存储路径 24 startActivityForResult(intent, 100); // 启动系统自带的拍照应用 25 } 26 27 public void takeVideo(View v) { 28 Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 29 intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri); 30 startActivityForResult(intent, 200); 31 } 32 33 @Override 34 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 35 switch (requestCode) { 36 case 100: 37 Toast.makeText(getApplicationContext(), "拍照成功: " + imageUri, Toast.LENGTH_SHORT).show(); 38 break; 39 case 200: 40 Toast.makeText(getApplicationContext(), "录像成功: " + videoUri, Toast.LENGTH_SHORT).show(); 41 break; 42 } 43 } 44 }
标签:
原文地址:http://www.cnblogs.com/friends-wf/p/4535006.html