Jim*_* D. 3 browser android file
我有一个应用程序,用户可以使用手机或SD上存储的图像选择个人资料图片.
我必须为此编写自己的文件浏览器吗?
我在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
归档时间: |
|
查看次数: |
2869 次 |
最近记录: |