获取手机拍照的图片或者录像的视频文件-路径方法(以时间来命名图片)

功能:
启动手机相机和摄像机
取出相机保存的图片路径
取出摄像机拍摄的视频文件路径
将摄像机拍摄的视频的作为UI的内容
//相机图片
            Intent iimg = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);// 跳转到系统相机
            *phoneFile* = new File(Environment.getExternalStorageDirectory()
                    .getAbsoluteFile() + "/" + **getTime()** + ".jpg");// 绝对路径+图片名称
            iimg.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(phoneFile));
            Log.d("TAG", phoneFile + "");// /storage/emulated/0/2016年12月07日 02:19:49.jpg

            //设置组件
            c_img = (ImageView) findViewById(R.id.c_img);
            Bitmap *bitmap* = BitmapFactory.decodeFile(*phoneFile*
                    .getAbsolutePath());
            c_img.setImageBitmap(*bitmap*);




//视频文件
            Intent video = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);// 跳转到系统相机
            *videoFile* = new File(Environment.getExternalStorageDirectory()
                    .getAbsoluteFile() + "/" + getTime() + ".mp4");// 绝对路径+图片名称
            video.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(videoFile));
            Log.d("TAG", *videoFile* + "");// /storage/emulated/0/2016年12月07日 02:19:49.jpg
            //设置组件
            v_video = (VideoView) findViewById(R.id.c_video);
            v_video.setVideoURI(Uri.fromFile(videoFile));
            v_video.start();


//获取当前时间
    private String **getTime()** {
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        Date date = new Date();
        String str = format.format(date);
        return str;
    }

你可能感兴趣的:(android,ui,手机相机,录像,路径)