我有一个应用程序,用户可以使用手机或SD上存储的图像选择个人资料图片. 我必须为此编写自己的文件浏览器吗? 我在anddev上看过几个例子,但不确定是否还有其他方法. 使用Intent.ACTIO
          我必须为此编写自己的文件浏览器吗?
我在anddev上看过几个例子,但不确定是否还有其他方法.
使用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()中获得选择.
更多参考:http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT
