zoukankan      html  css  js  c++  java
  • Android中通过Intent 调用图片、视频、音频、录音、拍照

    //选择图片 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);
  • 相关阅读:
    只知道参数名,要从对象里面获取值,可以使用反射机制获取
    mysql创建存储过程,批量建表分表00到99
    讲讲个人对于系统重构的一些心得
    浅谈线程runnable和callable的使用及区别
    springboot项目线程使用2
    springboot项目线程使用
    推荐一个算法网站
    Centos7.3安装和配置jre1.8转
    向java高级工程师和项目经理的道路进发【转】
    linux 查看日志命令
  • 原文地址:https://www.cnblogs.com/top5/p/2482235.html
Copyright © 2011-2022 走看看