0

Android lint keep reporting Missing Permissions even though I added @RequiresPermission on my method. Code is:

 @NonNull
    @RequiresPermission(Manifest.permission.READ_CONTACTS)
    public static Map<String, Integer> selectContactVersions(@Nullable Collection<String> contactIds) {
        if (!PermissionUtils.isPermissonGranted(ApplicationKeeper.getApplication(), Manifest.permission.READ_CONTACTS)) {
            return Collections.emptyMap();
        }

Error report is:

AddressAccesssor.java:41: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
  38   @RequiresPermission(Manifest.permission.READ_CONTACTS)
  39   public static Map<String, Integer> selectContactVersions(@Nullable Collection<String> contactIds) {
  40       if (!PermissionUtils.isPermissonGranted(ApplicationKeeper.getApplication(), Manifest.permission.READ_CONTACTS)) {
  41           return Collections.emptyMap();                                                          
  42       }


AddressAccessor.java:126: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
 123       return Collections.emptyMap();
 124   }
 125 
 126   Map<String, List<String>> contactIdPhoneListMap = selectPhones(contactIds);                 
 127 
 128   Map<String, AddressbookContact> addressbookContactMap = new HashMap<String, AddressbookContact>();
 129   Cursor cursor = null;

Did I miss something here?

Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59
John
  • 1,139
  • 3
  • 16
  • 33

1 Answers1

1

Did I miss something here?

Well, you missed a lot out there.

Permissions are required to be declared in manifest and needs to be requested in the run-time. Just suppressing the warning won't be enough.

Request the permissions explicitly to solve the problem.

Read the following documentation:
https://developer.android.com/training/permissions/requesting

Or simply use my library.

Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59