akexorcist / ScreenshotDetection

[Android] Screenshot detection while user using your app
Apache License 2.0
160 stars 33 forks source link

Fix a crash for CursorIndexOutOfBoundsException #10

Closed jason-hwang closed 2 years ago

jason-hwang commented 2 years ago

Problem

cursor.getString can make the CursorIndexOutOfBoundsException when the cursor's length of the database is zero.

Situation

The situation can happen when the READ_EXTERNAL_STORAGE permission is not allowed by the OS ( >= Android 12)

Solution

Add a guard for the case that the cursor's length of the database is zero.