要解决版本5.9.0更新相机胶卷的问题,可以尝试以下代码示例:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// 使用新的相机胶卷API
Uri collection = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
String[] projection = new String[]{MediaStore.Video.Media._ID, MediaStore.Video.Media.DISPLAY_NAME};
String selection = null;
String[] selectionArgs = null;
String sortOrder = null;
try (Cursor cursor = getContentResolver().query(collection, projection, selection, selectionArgs, sortOrder)) {
if (cursor != null) {
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID));
String name = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DISPLAY_NAME));
// 处理相机胶卷中的视频
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
// 使用旧的相机胶卷API
String[] projection = new String[]{MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA};
String selection = null;
String[] selectionArgs = null;
String sortOrder = null;
try (Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, sortOrder)) {
if (cursor != null) {
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media._ID));
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
// 处理相机胶卷中的图片
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// 使用新的相机胶卷API
Uri collection = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
String[] projection = new String[]{MediaStore.Video.Media._ID, MediaStore.Video.Media.DISPLAY_NAME};
String selection = null;
String[] selectionArgs = null;
String sortOrder = null;
try (Cursor cursor = getContentResolver().query(collection, projection, selection, selectionArgs, sortOrder)) {
if (cursor != null) {
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID));
String name = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DISPLAY_NAME));
// 使用Glide加载相机胶卷中的视频
Glide.with(this)
.load(Uri.withAppendedPath(collection, String.valueOf(id)))
.into(imageView);
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
// 使用旧的相机胶卷API
String[] projection = new String[]{MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA};
String selection = null;
String[] selectionArgs = null;
String sortOrder = null;
try (Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, sortOrder)) {
if (cursor != null) {
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media._ID));
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
// 使用Glide加载相机胶卷中的图片
Glide.with(this)
.load(Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, String.valueOf(id)))
.into(imageView);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
这些代码示例可以帮助您在版本5.9.0更新后处理相机胶卷的问题。根据您的需求和具体情况,可以适当修改代码。