Skip to content

Commit f2587b8

Browse files
committed
fix: resolve cursor bug
1 parent 9c8f9ed commit f2587b8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

android/src/main/java/flutter/plugins/contactsservice/contactsservice/ContactsServicePlugin.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,19 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent intent)
287287
return true;
288288
}
289289
Uri contactUri = intent.getData();
290+
Cursor cursor;
290291
if (intent != null){
291-
Cursor cursor = contentResolver.query(contactUri, null, null, null, null);
292-
if (cursor.moveToFirst()) {
292+
cursor = contentResolver.query(contactUri, null, null, null, null);
293+
if (cursor.moveToFirst()) {
293294
String id = contactUri.getLastPathSegment();
294295
getContacts("openDeviceContactPicker", id, false, false, false, localizedLabels, this.result);
295296
} else {
296297
Log.e(LOG_TAG, "onActivityResult - cursor.moveToFirst() returns false");
297298
finishWithResult(FORM_OPERATION_CANCELED);
298299
}}else{return true;}
299-
cursor.close();
300+
if (cursor != null) {
301+
cursor.close();
302+
}
300303
return true;
301304
}
302305

0 commit comments

Comments
 (0)