使用Intent.ACTION_GET_CONTENT为用户启动活动以选择所需的媒体类型.要选择图像,您可能需要MIME类型“image / *”.您还希望将其包装在一个选项中,因为通常会有多个内容源供用户选择(例如,他们可以浏览图库,或者可以在那时拍照,或者如果是的话可以使用通用文件浏览器安装等).
这是一些粗略的代码,可能是错误的,因为我只是在这里写出来:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
// Do this if you need to be able to open the returned URI as a stream
// (for example here to read the image data).
intent.addCategory(Intent.CATEGORY_OPENABLE);
Intent finalIntent = Intent.createChooser(intent, "Select profile picture");
startActivityForResult(finalIntent, IMAGE_SELECTED);
当用户选择了某些内容时,您将在onActivityResult()中获得选择.