I am using location services in my app, and where I am setting the permissions, I have this warning: Unchecked assignment: 'java.util.ArrayList' to 'java.util.ArrayList
Code:
permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
permissionsToRequest = findUnAskedPermissions(permissions);
The warning comes up on the last line.
I have defined the Arrays like this at the code start:
ArrayList<String> permissions = new ArrayList<>();
ArrayList<String> permissionsToRequest= new ArrayList<>();
ArrayList<String> permissionsRejected = new ArrayList<>();
Also later in my code, where I ask for the permission (if not allowed by user):
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (permissionsToRequest.size() > 0) {
requestPermissions(permissionsToRequest.toArray(new String[permissionsToRequest.size()]),
ALL_PERMISSIONS_RESULT);
canGetLocation = false;
}
}
here the toArray
causes the warning: Call to 'toArray()' with pre-sized array argument 'new String[permissionsToRequest.size()]
Here I can try to replace it with
toArray(new String[0])
but not sure if it is correct.