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

android.database.CursorIndexOutOfBoundsException #9

Open
wahyukharisma opened this issue Jan 11, 2022 · 1 comment
Open

android.database.CursorIndexOutOfBoundsException #9

wahyukharisma opened this issue Jan 11, 2022 · 1 comment

Comments

@wahyukharisma
Copy link

I found this error in some devices like Samsung, Xiaomi, Oppo, and Realme

com.akexorcist.screenshotdetection.ScreenshotDetectionDelegate.getFilePathFromContentResolver (ScreenshotDetectionDelegate.kt:142)
com.akexorcist.screenshotdetection.ScreenshotDetectionDelegate.onContentChanged (ScreenshotDetectionDelegate.kt:107)
com.akexorcist.screenshotdetection.ScreenshotDetectionDelegate.access$onContentChanged (ScreenshotDetectionDelegate.kt:32)
com.akexorcist.screenshotdetection.ScreenshotDetectionDelegate$startScreenshotDetection$1$invokeSuspend$$inlined$collect$1.emit (Collect.kt:133)
kotlinx.coroutines.flow.FlowKt__DelayKt$debounceInternal$1$3$1.invokeSuspend (Delay.kt:235)

@jason-hwang
Copy link

jason-hwang commented Apr 29, 2022

Same here.

I've fixed the related codes like this:

@Suppress("DEPRECATION")
private fun getFilePathFromContentResolver(context: Context, uri: Uri): String? {
    try {
        context.contentResolver.query(
          ...
        )?.let { cursor ->
            cursor.moveToFirst()
            if (cursor.count > 0) {
                val columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA)
                var path: String? = null
                if (columnIndex > 0) {
                    path = cursor.getString(columnIndex)
                }
                cursor.close()
                return path
            }
            cursor.close()
            return null
        }
    } catch (e: Exception) {
        Log.w(TAG, e.message ?: "")
    }
    return null
}

How about this idea? to fix the exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants