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

本文介绍如何使用 Android 中的 Intent 来实现多种功能,包括选择图片、添加音频、拍摄视频及照片、录制音频等常见操作。提供了详细的代码示例,帮助开发者快速掌握 Intent 的使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. <span style="font-size:18px;">我们在做一些东西的时候会必不可少的调用系统自带设备功能,比如一些视频,拍照一类所以这里总结了一些常见的功能通过Intent 调用的用法!</span>  
[java]  view plain copy
  1. //选择图片 requestCode 返回的标识  
  2. Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //"android.intent.action.GET_CONTENT"  
  3. intent.setType(contentType); //查看类型 String IMAGE_UNSPECIFIED = "image/*";  
  4. Intent wrapperIntent = Intent.createChooser(intent, null);  
  5. ((Activity) context).startActivityForResult(wrapperIntent, requestCode);  
  6.   
  7. //添加音频  
  8. Intent intent = new Intent(Intent.ACTION_GET_CONTENT);  
  9. intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";  
  10. Intent wrapperIntent = Intent.createChooser(intent, null);  
  11. ((Activity) context).startActivityForResult(wrapperIntent, requestCode);  
  12.   
  13. //拍摄视频  
  14. int durationLimit = getVideoCaptureDurationLimit(); //SystemProperties.getInt("ro.media.enc.lprof.duration", 60);  
  15. Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);  
  16. intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);  
  17. intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit);  
  18. intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationLimit);  
  19. startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);  
  20.   
  21. //视频  
  22. Intent intent = new Intent(Intent.ACTION_GET_CONTENT);  
  23. intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";  
  24. Intent wrapperIntent = Intent.createChooser(intent, null);  
  25. ((Activity) context).startActivityForResult(wrapperIntent, requestCode);  
  26.   
  27. //录音  
  28. Intent intent = new Intent(Intent.ACTION_GET_CONTENT);  
  29. intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = "audio/amr";  
  30. intent.setClassName("com.android.soundrecorder",  
  31. "com.android.soundrecorder.SoundRecorder");  
  32. ((Activity) context).startActivityForResult(intent, requestCode);  
  33.   
  34. //拍照 REQUEST_CODE_TAKE_PICTURE 为返回的标识  
  35. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //"android.media.action.IMAGE_CAPTURE";  
  36. intent.putExtra(MediaStore.EXTRA_OUTPUT, Mms.ScrapSpace.CONTENT_URI); // output,Uri.parse("content://mms/scrapSpace");  
  37. startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值