Android 巧用Itent.ACTION_PICK和Intent.ACTION_GET_CONTENT(三)

来源:互联网 发布:开发程序员 编辑:程序博客网 时间:2024/06/06 17:44
 此外:

java代码:

  1. //选择图片 requestCode 返回的标识 

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

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

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

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


  6. //视频
  7. Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT);
  8. innerIntent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
  9. Intent wrapperIntent = Intent.createChooser(innerIntent, null);
  10. ((Activity) context).startActivityForResult(wrapperIntent, requestCode);

  11. //添加音频
  12. Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT);
  13. innerIntent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
  14. Intent wrapperIntent = Intent.createChooser(innerIntent, null);
  15. ((Activity) context).startActivityForResult(wrapperIntent, requestCode);

  16. //录音
  17. Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
  18. intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = "audio/amr";
  19. intent.setClassName("com.android.soundrecorder","com.android.soundrecorder.SoundRecorder");
  20. ((Activity) context).startActivityForResult(intent, requestCode);

  21. //拍摄视频
  22. int durationLimit = getVideoCaptureDurationLimit(); 
  23. //SystemProperties.getInt("ro.media.enc.lprof.duration", 60);
  24. Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
  25. intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
  26. intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit);
  27. intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationLimit);
  28. startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);

  29. //拍照 REQUEST_CODE_TAKE_PICTURE 为返回的标识
  30. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //"android.media.action.IMAGE_CAPTURE";

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

  32. startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);

复制代码