<NME> ContactsActivity.java
<BEF> package cgeo.contacts;

import cgeo.contacts.permission.PermissionHandler;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.provider.ContactsContract;
import android.util.Log;
import android.util.Pair;
import android.view.Gravity;
import android.widget.Toast;

import androidx.annotation.NonNull;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
    static final String LOG_TAG = "cgeo.contacts";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final Uri uri = getIntent().getData();
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final Uri uri = getIntent().getData();
        if (uri == null) {
            finish();
            return;
        }

        nickName = getParameter(uri, IContacts.PARAM_NAME);
        if (StringUtils.isEmpty(nickName)) {
            finish();
            return;
        }

        final boolean hasPermission = PermissionHandler.requestContactsPermission(this);
        if (hasPermission) {
            searchUser();
        }
        // else -> onRequestPermissionsResult()
    }

    @Override
    public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
        if (grantResults.length > 0) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                searchUser();
            } else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
                PermissionHandler.askAgainFor(this, requestCode);
            }
        }
    }
            selectContact(contacts);
        }
        else {
            int contactId = contacts.get(0).first;
            openContactAndFinish(contactId);
        }
    }

    private void selectContact(final List<Pair<Integer, String>> contacts) {
        List<String> list = new ArrayList<>();
        for (Pair<Integer, String> p : contacts) {
            list.add(p.second);
        }
        final CharSequence[] items = list.toArray(new CharSequence[list.size()]);
        }
                .setTitle(R.string.multiple_matches)
                .setItems(items, new OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        int contactId = contacts.get(which).first;
                        dialog.dismiss();
                        openContactAndFinish(contactId);
                    }
        } else {
                .create().show();
    }

    private void openContactAndFinish(int id) {
        final Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(id));
        intent.setData(uri);
        startActivity(intent);
        finish();
    }

    private List<Pair<Integer, String>> getContacts(final @NonNull String searchName, Uri uri, final @NonNull String idColumnName, final @NonNull String selectionColumnName, boolean like) {
        final String[] projection = new String[] { idColumnName, selectionColumnName };
        final String selection = selectionColumnName + (like ? " LIKE" : " =") + " ? COLLATE NOCASE";
        final String[] selectionArgs = new String[] { like ? "%" + searchName + "%" : searchName };
        Cursor cursor = null;

        List<Pair<Integer, String>> result = new ArrayList<>();
        try {
            cursor = getContentResolver().query(uri, projection, selection, selectionArgs, null);
            while (cursor != null && cursor.moveToNext()) {
                int foundId = cursor.getInt(0);
                String foundName = cursor.getString(1);
                result.add(new Pair<>(foundId, foundName));
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, "ContactsActivity.getContactId", e);
        } finally {
            if (cursor != null) {
        startActivity(intent);
        finish();
    }

    @NonNull
    private List<Pair<Integer, String>> getContacts(@NonNull final String searchName, final Uri uri, @NonNull final String idColumnName, @NonNull final String selectionColumnName, final boolean like) {
        final String[] projection = {idColumnName, selectionColumnName, ContactsContract.Contacts.DISPLAY_NAME};
        final String selection = selectionColumnName + (like ? " LIKE" : " =") + " ? COLLATE NOCASE";
        final String[] selectionArgs = {like ? "%" + searchName + "%" : searchName};

        final List<Pair<Integer, String>> result = new ArrayList<>();
        try (Cursor cursor = getContentResolver().query(uri, projection, selection, selectionArgs, null)) {
            while (cursor != null && cursor.moveToNext()) {
                final int foundId = cursor.getInt(0);
                final String foundName = cursor.getString(1);
                final String displayName = cursor.getString(2);
                result.add(new Pair<>(foundId, StringUtils.isNotEmpty(displayName) &&
                return StringUtils.EMPTY;
            }
            return URLDecoder.decode(param, CharEncoding.UTF_8).trim();
        } catch (UnsupportedEncodingException e) {
            Log.e(LOG_TAG, "ContactsActivity.getParameter", e);
        }
        return StringUtils.EMPTY;
    }

    public void showToast(final String text) {
        final Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG);

        toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 100);
        toast.show();
    }

    @NonNull
    private static String getParameter(@NonNull final Uri uri, @NonNull final String paramKey) {
        try {
            final String param = uri.getQueryParameter(paramKey);
            if (param == null) {
                return StringUtils.EMPTY;
            }
            return URLDecoder.decode(param, StandardCharsets.UTF_8.name()).trim();
        } catch (final UnsupportedEncodingException e) {
            Log.e(LOG_TAG, "ContactsActivity.getParameter", e);
        }
        return StringUtils.EMPTY;
    }

}

<MSG> some code cleanups with Android Studio

<DFF> @@ -28,7 +28,7 @@ public final class ContactsActivity extends Activity {
     static final String LOG_TAG = "cgeo.contacts";
 
     @Override
-    public void onCreate(Bundle savedInstanceState) {
+    public void onCreate(final Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         final Uri uri = getIntent().getData();
@@ -67,14 +67,14 @@ public final class ContactsActivity extends Activity {
             selectContact(contacts);
         }
         else {
-            int contactId = contacts.get(0).first;
+            final int contactId = contacts.get(0).first;
             openContactAndFinish(contactId);
         }
     }
 
     private void selectContact(final List<Pair<Integer, String>> contacts) {
-        List<String> list = new ArrayList<>();
-        for (Pair<Integer, String> p : contacts) {
+        final List<String> list = new ArrayList<>();
+        for (final Pair<Integer, String> p : contacts) {
             list.add(p.second);
         }
         final CharSequence[] items = list.toArray(new CharSequence[list.size()]);
@@ -82,8 +82,9 @@ public final class ContactsActivity extends Activity {
                 .setTitle(R.string.multiple_matches)
                 .setItems(items, new OnClickListener() {
 
-                    public void onClick(DialogInterface dialog, int which) {
-                        int contactId = contacts.get(which).first;
+                    @Override
+                    public void onClick(final DialogInterface dialog, final int which) {
+                        final int contactId = contacts.get(which).first;
                         dialog.dismiss();
                         openContactAndFinish(contactId);
                     }
@@ -91,29 +92,29 @@ public final class ContactsActivity extends Activity {
                 .create().show();
     }
 
-    private void openContactAndFinish(int id) {
+    private void openContactAndFinish(final int id) {
         final Intent intent = new Intent(Intent.ACTION_VIEW);
-        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(id));
+        final Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(id));
         intent.setData(uri);
         startActivity(intent);
         finish();
     }
 
-    private List<Pair<Integer, String>> getContacts(final @NonNull String searchName, Uri uri, final @NonNull String idColumnName, final @NonNull String selectionColumnName, boolean like) {
+    private List<Pair<Integer, String>> getContacts(final @NonNull String searchName, final Uri uri, final @NonNull String idColumnName, final @NonNull String selectionColumnName, final boolean like) {
         final String[] projection = new String[] { idColumnName, selectionColumnName };
         final String selection = selectionColumnName + (like ? " LIKE" : " =") + " ? COLLATE NOCASE";
         final String[] selectionArgs = new String[] { like ? "%" + searchName + "%" : searchName };
         Cursor cursor = null;
 
-        List<Pair<Integer, String>> result = new ArrayList<>();
+        final List<Pair<Integer, String>> result = new ArrayList<>();
         try {
             cursor = getContentResolver().query(uri, projection, selection, selectionArgs, null);
             while (cursor != null && cursor.moveToNext()) {
-                int foundId = cursor.getInt(0);
-                String foundName = cursor.getString(1);
+                final int foundId = cursor.getInt(0);
+                final String foundName = cursor.getString(1);
                 result.add(new Pair<>(foundId, foundName));
             }
-        } catch (Exception e) {
+        } catch (final Exception e) {
             Log.e(LOG_TAG, "ContactsActivity.getContactId", e);
         } finally {
             if (cursor != null) {
@@ -137,7 +138,7 @@ public final class ContactsActivity extends Activity {
                 return StringUtils.EMPTY;
             }
             return URLDecoder.decode(param, CharEncoding.UTF_8).trim();
-        } catch (UnsupportedEncodingException e) {
+        } catch (final UnsupportedEncodingException e) {
             Log.e(LOG_TAG, "ContactsActivity.getParameter", e);
         }
         return StringUtils.EMPTY;

some code cleanups with Android Studio