-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android Q适配问题 #602
Comments
以下是我的改版,针对targetSdkVersion为29的适配。 public class AlbumLoader extends CursorLoader {
public static final String COLUMN_COUNT = "count";
private static final Uri QUERY_URI = MediaStore.Files.getContentUri("external");
private static final String COLUMN_BUCKET_ID = "bucket_id";
private static final String COLUMN_BUCKET_NAME = "bucket_display_name";
private static final String[] COLUMNS = {
MediaStore.Files.FileColumns._ID,
COLUMN_BUCKET_ID,
COLUMN_BUCKET_NAME,
MediaStore.MediaColumns.DATA,
COLUMN_COUNT};
private static final String[] PROJECTION = {
MediaStore.Files.FileColumns._ID,
COLUMN_BUCKET_ID,
COLUMN_BUCKET_NAME,
MediaStore.MediaColumns.DATA};
// === params for showSingleMediaType: false ===
private static final String SELECTION =
"(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
+ " OR "
+ MediaStore.Files.FileColumns.MEDIA_TYPE + "=?)"
+ " AND " + MediaStore.MediaColumns.SIZE + ">0";
private static final String[] SELECTION_ARGS = {
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
};
// =============================================
// === params for showSingleMediaType: true ===
private static final String SELECTION_FOR_SINGLE_MEDIA_TYPE =
MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
+ " AND " + MediaStore.MediaColumns.SIZE + ">0";
private static String[] getSelectionArgsForSingleMediaType(int mediaType) {
return new String[]{String.valueOf(mediaType)};
}
// =============================================
private static final String BUCKET_ORDER_BY = "datetaken DESC";
private AlbumLoader(Context context, String selection, String[] selectionArgs) {
super(context, QUERY_URI, PROJECTION, selection, selectionArgs, BUCKET_ORDER_BY);
}
public static CursorLoader newInstance(Context context) {
String selection;
String[] selectionArgs;
if (SelectionSpec.getInstance().onlyShowImages()) {
selection = SELECTION_FOR_SINGLE_MEDIA_TYPE;
selectionArgs = getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
} else if (SelectionSpec.getInstance().onlyShowVideos()) {
selection = SELECTION_FOR_SINGLE_MEDIA_TYPE;
selectionArgs = getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO);
} else {
selection = SELECTION;
selectionArgs = SELECTION_ARGS;
}
return new AlbumLoader(context, selection, selectionArgs);
}
@Override
public Cursor loadInBackground() {
Cursor cursor = super.loadInBackground();
MatrixCursor albumCursor = new MatrixCursor(COLUMNS);
if (cursor == null) {
return albumCursor;
}
int totalCount = cursor.getCount();
boolean allAdded = false;
SparseArray<Album> albums = new SparseArray<>();
while (cursor.moveToNext()) {
String filepath = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA));
int bucketId = cursor.getInt(cursor.getColumnIndex(COLUMN_BUCKET_ID));
String bucketName = cursor.getString(cursor.getColumnIndex(COLUMN_BUCKET_NAME));
if (!allAdded) {
albumCursor.addRow(new String[]{ALBUM_ID_ALL, ALBUM_ID_ALL, ALBUM_NAME_ALL, filepath, String.valueOf(totalCount)});
allAdded = true;
}
Album album = albums.get(bucketId);
if (album == null) {
album = new Album(bucketId + "", filepath, bucketName, 0);
albums.append(bucketId, album);
}
album.addCaptureCount();
}
for (int i = 0; i < albums.size(); i++) {
Album album = albums.valueAt(i);
String id = album.getId();
String name = album.getDisplayName(getContext());
String coverPath = album.getCoverPath();
String count = album.getCount() + "";
albumCursor.addRow(new String[]{id, id, name, coverPath, count});
}
return albumCursor;
}
@Override
public void onContentChanged() {
// FIXME a dirty way to fix loading multiple times
}
} |
pr is welcome |
@belinwu 有一个问题,我有些疑惑,在Android10上面 MediaStore.MediaColumns.DATA 这个字段其实是拿不到的。在Android Q上面运行没问题么。 |
确实DATA字段值在Q上不可靠,之后没有直接使用该值,用的是Content Uri。 |
@belinwu 我发现DATA值不可靠后,我也是通过Uri获取。但是我发现一个问题 图库里面有一些图片我获取的Uri无法读取图片。。。 |
你试拍照了么? |
等待适配androidQ 方案 |
有何进展吗?望告知下 |
并没有 只能改targetSdkVersion不为29
…------------------ 原始邮件 ------------------
发件人: "thirtyyuan"<[email protected]>;
发送时间: 2020年1月7日(星期二) 晚上8:04
收件人: "zhihu/Matisse"<[email protected]>;
抄送: "1838827355"<[email protected]>;"Comment"<[email protected]>;
主题: Re: [zhihu/Matisse] Android Q适配问题 (#602)
有何进展吗?望告知下
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Android Q编译的APK,在Pixel3的Android Q系统上报错,具体信息如下:
配置:
compileSdkVersion 'android-Q'
minSdkVersion 'Q'
targetSdkVersion 'Q'
错误:
E/DatabaseUtils: Writing exception to parcel
java.lang.IllegalArgumentException: Invalid column bucket_id
at android.database.sqlite.SQLiteQueryBuilder.computeProjection(SQLiteQueryBuilder.java:886)
at android.database.sqlite.SQLiteQueryBuilder.buildQuery(SQLiteQueryBuilder.java:664)
at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:463)
at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:377)
at android.database.TranslatingCursor.query(TranslatingCursor.java:119)
at com.android.providers.media.MediaProvider.query(MediaProvider.java:1447)
at android.content.ContentProvider$Transport.query(ContentProvider.java:267)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:104)
at android.os.Binder.execTransactInternal(Binder.java:1026)
at android.os.Binder.execTransact(Binder.java:999)
请适配一下!
The text was updated successfully, but these errors were encountered: