Skip to content
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

fix: fix build error with api 33 and add patch file changes #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ReactNativeCameraRoll_compileSdkVersion=28
ReactNativeCameraRoll_buildToolsVersion=28.0.3
ReactNativeCameraRoll_targetSdkVersion=27
ReactNativeCameraRoll_minSdkVersion=16
ReactNativeCameraRoll_compileSdkVersion=33
ReactNativeCameraRoll_buildToolsVersion=29.0.2
ReactNativeCameraRoll_targetSdkVersion=33
ReactNativeCameraRoll_minSdkVersion=23
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package com.reactnativecommunity.cameraroll;

import android.os.Bundle;
import android.os.Build;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
Expand Down Expand Up @@ -378,19 +380,36 @@ protected void doInBackgroundGuarded(Void... params) {
ContentResolver resolver = mContext.getContentResolver();

try {
// set LIMIT to first + 1 so that we know how to populate page_info
String limit = "limit=" + (mFirst + 1);

if (!TextUtils.isEmpty(mAfter)) {
limit = "limit=" + mAfter + "," + (mFirst + 1);
Cursor media;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Bundle bundle = new Bundle();
bundle.putString(ContentResolver.QUERY_ARG_SQL_SELECTION, selection.toString());
bundle.putStringArray(ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS,
selectionArgs.toArray(new String[selectionArgs.size()]));
bundle.putString(ContentResolver.QUERY_ARG_SQL_SORT_ORDER, Images.Media.DATE_ADDED + " DESC, " + Images.Media.DATE_MODIFIED + " DESC");
bundle.putInt(ContentResolver.QUERY_ARG_LIMIT, mFirst + 1);
if (!TextUtils.isEmpty(mAfter)) {
bundle.putInt(ContentResolver.QUERY_ARG_OFFSET, Integer.parseInt(mAfter));
}
media = resolver.query(
MediaStore.Files.getContentUri("external"),
PROJECTION,
bundle,
null);
} else {
// set LIMIT to first + 1 so that we know how to populate page_info
String limit = "limit=" + (mFirst + 1);
if (!TextUtils.isEmpty(mAfter)) {
limit = "limit=" + mAfter + "," + (mFirst + 1);
}
media = resolver.query(
MediaStore.Files.getContentUri("external").buildUpon().encodedQuery(limit).build(),
PROJECTION,
selection.toString(),
selectionArgs.toArray(new String[selectionArgs.size()]),
Images.Media.DATE_ADDED + " DESC, " + Images.Media.DATE_MODIFIED + " DESC");
}

Cursor media = resolver.query(
MediaStore.Files.getContentUri("external").buildUpon().encodedQuery(limit).build(),
PROJECTION,
selection.toString(),
selectionArgs.toArray(new String[selectionArgs.size()]),
Images.Media.DATE_ADDED + " DESC, " + Images.Media.DATE_MODIFIED + " DESC");
if (media == null) {
mPromise.reject(ERROR_UNABLE_TO_LOAD, "Could not get media");
} else {
Expand Down Expand Up @@ -576,7 +595,9 @@ private static boolean putImageInfo(
boolean includeImageSize,
boolean includePlayableDuration) {
WritableMap image = new WritableNativeMap();
Uri photoUri = Uri.parse("file://" + media.getString(dataIndex));
// Uri photoUri = Uri.parse("file://" + media.getString(dataIndex));
Uri externalUri = MediaStore.Files.getContentUri("external");
Uri photoUri = ContentUris.withAppendedId(externalUri, media.getLong(media.getColumnIndexOrThrow(Images.Media._ID)));
image.putString("uri", photoUri.toString());
String mimeType = media.getString(mimeTypeIndex);

Expand Down Expand Up @@ -649,7 +670,11 @@ private static boolean putPlayableDuration(
+ photoUri.toString(),
e);
}
retriever.release();
try {
retriever.release();
} catch (IOException e) {
// Do nothing. We can't handle this, and this is usually a system problem
}
}

if (photoDescriptor != null) {
Expand Down Expand Up @@ -719,7 +744,11 @@ private static boolean putImageSize(
+ photoUri.toString(),
e);
}
retriever.release();
try {
retriever.release();
} catch (IOException e) {
// Do nothing. We can't handle this, and this is usually a system problem
}
} else {
BitmapFactory.Options options = new BitmapFactory.Options();
// Set inJustDecodeBounds to true so we don't actually load the Bitmap, but only get its
Expand Down