您的位置:首页 > 移动开发 > Android开发

android调用系统的图片,视频,音频,录音,拍照

2014-08-30 10:35 681 查看
//选择图片 requestCode 返回的标识

  Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT); //"android.intent.action.GET_CONTENT"

  innerIntent.setType(contentType); //查看类型 String IMAGE_UNSPECIFIED = "image/*";

  Intent wrapperIntent = Intent.createChooser(innerIntent, null);

  ((Activity) context).startActivityForResult(wrapperIntent, requestCode);

  //视频

  Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT);

  innerIntent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";

  Intent wrapperIntent = Intent.createChooser(innerIntent, null);

  ((Activity) context).startActivityForResult(wrapperIntent, requestCode);

 //添加音频

  Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT);

  innerIntent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";

  Intent wrapperIntent = Intent.createChooser(innerIntent, null);

  ((Activity) context).startActivityForResult(wrapperIntent, requestCode);

 //录音

//Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); startActivityForResult(intent, 0);

  Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

  intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = "audio/amr";

  intent.setClassName("com.android.soundrecorder",

  "com.android.soundrecorder.SoundRecorder");

  ((Activity) context).startActivityForResult(intent, requestCode);

  //拍摄视频

  int durationLimit = getVideoCaptureDurationLimit(); //SystemProperties.getInt("ro.media.enc.lprof.duration", 60);

  Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

  intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);

  intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit);

  intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationLimit);

  startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);

  //拍照 REQUEST_CODE_TAKE_PICTURE 为返回的标识

  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //"android.media.action.IMAGE_CAPTURE";

  intent.putExtra(MediaStore.EXTRA_OUTPUT, Mms.ScrapSpace.CONTENT_URI); // output,Uri.parse("content://mms/scrapSpace");

  startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);

//获取路径

Uri uri = data.getData();

String[] filePathColumn = { MediaStore.Audio.Media.DATA };

Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);

cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);

audioPath = cursor.getString(columnIndex);

cursor.close();

调用系统图库看图片

Intent intent = new Intent();

intent.setAction(android.content.Intent.ACTION_VIEW);

intent.setDataAndType(Uri.fromFile(file), "image/*");

startActivity(intent);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐