我的问题只发生在我的平板电脑上; Nexus 7 6.0.1 它不在我的手机上; Galaxy S6 5.0.2
我有一种方法来获取外部sd上的所有图像,如下所示
private ArrayList<String> getAllImages(Activity activity) {
Uri uri;
Cursor cursor;
int columnIndexData;
listOfAllImages = new ArrayList<>();
String absolutePath;
uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME};
cursor = activity.getContentResolver().query(uri, projection, null, null, null);
columnIndexData = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
while (cursor.moveToNext()) {
absolutePath = cursor.getString(columnIndexData);
listOfAllImages.add(absolutePath);
}
listOfAllImages.add("camera"); //this is where the 'take picture' will be
Collections.reverse(listOfAllImages);
Log.d(TAG, "images " + listOfAllImages.toString());
cursor.close();
return listOfAllImages;
}
我启动了像这样的照片捕捉意图
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
getActivity().startActivityForResult(takePicture, 1);
然后在结果中,我只是调用一个设置方法再次调用上面的“获取所有图像”功能,然后选择位置1,这是新拍摄的图像。它在我的手机上工作正常但不是平板电脑。如果我使用平板电脑上的普通相机应用程序拍照,它会显示在“listOfAllImages”中......但不会在执行意图时显示。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "Take Picture result. " + requestCode + " " + resultCode + " " + data);
if (requestCode == 1) {
//means we took a picture, and the result was good
if (resultCode == Activity.RESULT_OK) {
try {
setupGalleryView();
imagesGridView.performItemClick(
imagesGridView.getAdapter().getView(1, null, null),
1,
imagesGridView.getAdapter().getItemId(1));
} catch (NullPointerException e) {
Log.d(TAG, "activity result, camera, exception " + e.getMessage());
app.showAlertDialog(context, "There was a problem obtaining image data.");
e.printStackTrace();
}
}
}
}
不完全确定要搜索的内容,因此Google /其他SO帖子并没有太大帮助。有人有什么想法吗?