Android中通过Intent 调用图片、视频、音频、录音、拍照

1. android中的一个隐藏的类:ContentType,其中定义了android支持的mimetype类型
  类的路径: com.google.android.mms.ContentType
2. Action为Intent.ACTION_GET_CONTENT的Intent可以设置许多参数,如:
  intent.putExtra("crop", "true");
        intent.putExtra("outputX", appsWallpaperWidth);
        intent.putExtra("outputY", apps_wallpaper_height);
        intent.putExtra("aspectX", appsWallpaperWidth);
        intent.putExtra("aspectY", apps_wallpaper_height);
        intent.putExtra("scale", true);
        intent.putExtra("noFaceDetection", true);
        intent.putExtra("output", appsWallpaperPath);
        intent.putExtra("outputFormat", "JPEG");
3. 使用startActivityForResult方法启动Intent对应的Activity,可以在原Activity的回调方法onActivityResult方法中拿到返回的数据.返回的数据放在第三个参数data(Intnet类型)中.
  使用getData返回一个Uri,再使用context.getContentResolver().openInputStream(uri);可以拿到一个输入流.
  
//选择图片 requestCode 返回的标识
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //"android.intent.action.GET_CONTENT"
intent.setType(contentType); //查看类型 String IMAGE_UNSPECIFIED = "image/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);
 
//添加音频
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, 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);
 
//视频
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);
 
//录音
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);
 
//拍照 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);

参考:
  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值