@@ -499,32 +499,35 @@ private void handleContactResult(@NonNull Uri contactUri) {
499499 String [] projection = {ContactsContract .CommonDataKinds .Email .ADDRESS };
500500
501501 Cursor cursor = getContentResolver ().query (contactUri , projection , null , null , null );
502+ if (cursor == null ) {
503+ DisplayUtils .showSnackMessage (this , getString (R .string .email_pick_failed ));
504+ Log_OC .e (TAG , "Failed to pick email address as Cursor is null." );
505+ return ;
506+ }
502507
503- if (cursor != null ) {
504- if (cursor .moveToFirst ()) {
505- // The contact has only one email address, use it.
506- int columnIndex = cursor .getColumnIndex (ContactsContract .CommonDataKinds .Email .ADDRESS );
507- if (columnIndex != -1 ) {
508- // Use the email address as needed.
509- // email variable contains the selected contact's email address.
510- String email = cursor .getString (columnIndex );
511- binding .searchView .post (() -> {
512- binding .searchView .setQuery (email , false );
513- binding .searchView .requestFocus ();
514- });
515- } else {
516- DisplayUtils .showSnackMessage (this , getString (R .string .email_pick_failed ));
517- Log_OC .e (NoteShareActivity .class .getSimpleName (), "Failed to pick email address." );
518- }
519- } else {
520- DisplayUtils .showSnackMessage (this , getString (R .string .email_pick_failed ));
521- Log_OC .e (NoteShareActivity .class .getSimpleName (), "Failed to pick email address as no Email found." );
522- }
523- cursor .close ();
524- } else {
508+ if (!cursor .moveToFirst ()) {
525509 DisplayUtils .showSnackMessage (this , getString (R .string .email_pick_failed ));
526- Log_OC .e (NoteShareActivity .class .getSimpleName (), "Failed to pick email address as Cursor is null." );
510+ Log_OC .e (TAG , "Failed to pick email address as no Email found." );
511+ return ;
512+ }
513+
514+ // The contact has only one email address, use it.
515+ int columnIndex = cursor .getColumnIndex (ContactsContract .CommonDataKinds .Email .ADDRESS );
516+ if (columnIndex == -1 ) {
517+ DisplayUtils .showSnackMessage (this , getString (R .string .email_pick_failed ));
518+ Log_OC .e (TAG , "Failed to pick email address." );
519+ return ;
527520 }
521+
522+ // Use the email address as needed.
523+ // email variable contains the selected contact's email address.
524+ String email = cursor .getString (columnIndex );
525+ binding .searchView .post (() -> {
526+ binding .searchView .setQuery (email , false );
527+ binding .searchView .requestFocus ();
528+ });
529+
530+ cursor .close ();
528531 }
529532
530533 private boolean containsNoNewPublicShare (List <OCShare > shares ) {
0 commit comments