[Android] Check cursor validity and close it properly

Geoffrey Métais git at videolan.org
Mon May 25 11:42:25 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 25 10:41:49 2015 +0200| [9cdcdafeb7aedf7a0b8e2d1697c1f62dec71cb16] | committer: Geoffrey Métais

Check cursor validity and close it properly

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=9cdcdafeb7aedf7a0b8e2d1697c1f62dec71cb16
---

 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.java  |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 4550ddf..c0840fc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2744,11 +2744,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
 
                         Cursor returnCursor =
                                 getContentResolver().query(data, null, null, null, null);
-                        if (returnCursor != null) {
+                        if (returnCursor != null && returnCursor.getCount() > 0) {
                             int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
-                            int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
-                            returnCursor.moveToFirst();
-                            title = returnCursor.getString(nameIndex);
+                            if (nameIndex > -1) {
+                                returnCursor.moveToFirst();
+                                title = returnCursor.getString(nameIndex);
+                            }
+                            returnCursor.close();
                         }
                     } catch (FileNotFoundException e) {
                         Log.e(TAG, "Couldn't understand the intent");



More information about the Android mailing list