gpt4 book ai didi

java - Android:MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA

转载 作者:行者123 更新时间:2023-12-01 14:35:04 27 4
gpt4 key购买 nike

谁能给我指导如何找到我的 Android 设备存储从相机拍摄的图像的目录;

在下面的代码 fragment 中,我打算在启动相机应用程序之前获取文件列表。从相机应用程序返回时,获取同一目录中所有文件的列表并处理新添加的文件。

public void onBtnTakePhoto(final View view) {
existingfiles = UploadImageService.getFiles(<IMAGE_LOCATION>);
final Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
startActivityForResult(intent, TAKE_PICTURE);
}


public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);

switch (requestCode) {
case TAKE_PICTURE:
List<String> newFies = UploadImageService.getFiles(<IMAGE_LOCATION>);
newFies.removeAll(existingfiles);
for (String newFile : newFies) {
File file = new File(newFile);
addImage( Uri.fromFile(file), PictureSource.CAMERA);
}
break;
}
// regardless of which activity, check that files exist:
verifyFilesExist(images);
}

最佳答案

据我了解,您实际上必须使用 ACTION_IMAGE_CAPTURE 来启动您的 Intent 。 Action (而不是 INTENT_ACTION_STILL_IMAGE_CAMERA)。然后,在 onActivityResult 中,您必须从 Intent 获取数据:在那里您将找到对图像的引用。

看看给出的例子here .

但是当我查看您的答案时,您可能会发现这更有用:

String[] projection = { 
MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA
};
String selection = "";
String[] selectionArgs = null;
mImageExternalCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, selection, selectionArgs, null);
mImageInternalCursor =
managedQuery(MediaStore.Images.Media.INTERNAL_CONTENT_URI, projection,
selection, selectionArgs, null);

然后

String filePath = 
mImageExternalCursor.getString(mImageExternalCursor.getColumnIndexOrThrow(
Media‌Store.Images.ImageColumns.DATA));

(因为您实际上并不想拍摄新照片)。

关于java - Android:MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16547542/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com