这个问题最初是针对Android 1.6提出的.
我在我的应用程序中处理照片选项.
我的Activity中有一个按钮和一个ImageView.当我点击按钮时,它会重定向到图库,我可以选择一个图像.所选图像将出现在我的ImageView中.
在KitKat之前(或在新Gallery之前)Intent.ACTION_GET_CONTENT返回这样的URI
内容://媒体/外部/图像/媒体/ 3951.
使用ContentResolver和quering
MediaStore.Images.Media.DATA返回文件URL.
但是在KitKat中,Gallery会返回一个URI(通过"Last"),如下所示:
内容://com.android.providers.media.documents/document/image:3951
我该如何处理?
android android-intent android-contentresolver android-gallery
我想做的事情似乎很简单,但经过几天的搜索,我无法弄明白.
我有一个应用程序,允许用户选择多个(最多5个)图像.我正在使用ImageView.当用户点击时ImageView,我想允许他们选择
我开始使用ACTION_GET_CONTENT意图,这对于进入画廊非常有用.那么我尝试使用ACTION_PICK_ACTIVITY意图允许用户选择相机或图库:
Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
Intent gallIntent=new Intent(Intent.ACTION_GET_CONTENT);
gallIntent.setType("image/*");
Intent camIntent = new Intent("android.media.action.IMAGE_CAPTURE");
pickIntent.putExtra(Intent.EXTRA_INTENT, camIntent);
pickIntent.putExtra(Intent.EXTRA_INTENT, gallIntent)
pickIntent.putExtra(Intent.EXTRA_TITLE, "Select Source");
startActivityForResult(pickIntent, IMAGE_SELECTOR);
Run Code Online (Sandbox Code Playgroud)
但似乎我只能添加一个EXTRA_INTENT.菜单按预期显示,但唯一的选项是图库和文件....没有相机).
有没有更好/更简单的方法来做到这一点,我错过了?谢谢你的帮助.
android android-intent android-gallery android-camera android-intent-chooser
我想实现Horizontal ScrollViewGallery的一些功能,

在画廊中,卷轴在一定距离处成对排列,即如果我们在屏幕上显示三个图像,则单击最后一个图像将排列在中心.
我将如何实施HorizontalSCrollView?
我想让用户从图库中选择个人资料图片.我的问题是有些图片是向右旋转的.
我像这样启动图像选择器:
Intent photoPickerIntent = new Intent();
photoPickerIntent.setType("image/*");
photoPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(photoPickerIntent, "Select profile picture"), Global.CODE_SELECT_PICTURE);
Run Code Online (Sandbox Code Playgroud)
我从onActivityResult获取图像,如下所示:
Uri selectedPicture = data.getData();
profilePic = MediaStore.Images.Media.getBitmap(activity.getContentResolver(), selectedPicture);
Run Code Online (Sandbox Code Playgroud)
如何让图像不被旋转?
更新:
根据我收到的一些有用的答案,我设法提出了以下工作解决方案(这只是一个工作代码,写得不好).我很想得到你如何改进它的反馈!
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == Global.CODE_SELECT_PICTURE) {
// Get selected gallery image
Uri selectedPicture = data.getData();
// Get and resize profile image
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = activity.getContentResolver().query(selectedPicture, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex); …Run Code Online (Sandbox Code Playgroud) 我的应用程序可以从库中选择照片.我想要从这个选择中获取文件路径.
这是创建选择照片的意图的代码:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, INTENT_REQUEST_CODE_SELECT_PHOTO);
Run Code Online (Sandbox Code Playgroud)
这是从URI获取文件路径的代码:
Cursor cursor = null;
String path = null;
try {
String[] projection = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(contentUri, projection, null, null, null);
int columnIndex = cursor.getColumnIndexOrThrow(projection[0]);
cursor.moveToFirst();
path = cursor.getString(columnIndex);
} finally {
if (cursor != null) {
cursor.close();
}
}
return path;
Run Code Online (Sandbox Code Playgroud)
在昨天更新Google相册应用之前,一切都运转良好.path解析URI后现在为null.
URI类似于: content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F75209/ACTUAL
我还试图用Intent.ACTION_GET_CONTENT动作创建意图 - 没有运气.
在一个Activity中,我可以从Gallery中选择一个图像,我需要它的Uri路径(在日志中,我的测试图像的Uri路径是/content:/media/external/images/media/1).
我收到这个错误但是:
08-04 02:14:21.912: DEBUG/PHOTOUPLOADER(576): java.io.FileNotFoundException: /content:/media/external/images/media/1 (No such file or directory)
08-04 02:14:32.124: WARN/System.err(576): java.io.FileNotFoundException: /content:/media/external/images/media/1 (No such file or directory)
Run Code Online (Sandbox Code Playgroud)
这是文件路径的正确格式吗?或者我应该做到这样sdcard\...\image.png吗?
我想在模拟器的库中添加图片.但我无法做到这一点.这该怎么做?任何线索!虽然我已经通过堆栈发布了一个回答流量但是没有通过该答案获得成功.
我正在从图库(相册)中选取的imageview上设置图像.如果摄取的图像具有横向,它显示完美,但如果在肖像模式(即图像被点击在纵向模式下),它会显示一个90度旋转图像的图像.现在我试图在设置imageview之前找出方向,但所有图像都给出相同的方向和相同的宽度 - 高度.这是我的代码:
Uri selectedImage = intent.getData();
if (selectedImage != null) {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
int str = new ExifInterface(selectedImage.getPath()).getAttributeInt("Orientation", 1000);
Toast.makeText(this, "value:" + str, Toast.LENGTH_LONG).show();
Toast.makeText(this, "width:" + bitmap.getWidth() + "height:" + bitmap.getHeight(), Toast.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)

我想得到从图库加载或从相机中拾取的图像的图像扩展名(例如"jpg","png","bmp"ecc.).
我已经使用此表单中的方法从库中加载图像
private static final int SELECT_PICTURE_ACTIVITY_REQUEST_CODE = 0;
....
private void selectPicture() {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, SELECT_PICTURE_ACTIVITY_REQUEST_CODE);
}
....
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch (requestCode) {
case SELECT_PICTURE_ACTIVITY_REQUEST_CODE:
if (resultCode == RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
if (cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
.........
} …Run Code Online (Sandbox Code Playgroud)