PermissionUtils can not be resolved

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



PermissionUtils can not be resolved



I'm trying to get my current location in my app but I'm getting PermissionUtils error. This isn't getting resolved. I got the codes from google's official github tutorial.


PermissionUtils


public class MapsActivity extends FragmentActivity implements GoogleMap.OnMyLocationButtonClickListener,
GoogleMap.OnMyLocationClickListener,
OnMapReadyCallback,
ActivityCompat.OnRequestPermissionsResultCallback

/**
* Request code for location permission request.
*
* @see #onRequestPermissionsResult(int, String, int)
*/
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;

/**
* Flag indicating whether a requested permission has been denied after returning in
* @link #onRequestPermissionsResult(int, String, int).
*/
private boolean mPermissionDenied = false;

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);

SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);




@Override
public void onMapReady(GoogleMap googleMap)
mMap = googleMap;

mMap.setOnMyLocationButtonClickListener(this);
mMap.setOnMyLocationClickListener(this);
enableMyLocation();



private void enableMyLocation()


if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED)
// Permission to access the location is missing.
PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE,
Manifest.permission.ACCESS_FINE_LOCATION, true);
else if (mMap != null)
// Access to the location has been granted to the app.
mMap.setMyLocationEnabled(true);




@Override
public boolean onMyLocationButtonClick()
Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT).show();
// Return false so that we don't consume the event and the default behavior still occurs
// (the camera animates to the user's current position).
return false;


@Override
public void onMyLocationClick(@NonNull Location location)
Toast.makeText(this, "Current location:n" + location, Toast.LENGTH_LONG).show();


@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions,
@NonNull int grantResults)

if (requestCode != LOCATION_PERMISSION_REQUEST_CODE)
return;


if (PermissionUtils.isPermissionGranted(permissions, grantResults,
Manifest.permission.ACCESS_FINE_LOCATION))
// Enable the my location layer if the permission has been granted.
enableMyLocation();
else
// Display the missing permission error dialog when the fragments resume.
mPermissionDenied = true;



@Override
protected void onResumeFragments()
super.onResumeFragments();
if (mPermissionDenied)
// Permission was not granted, display error dialog.
showMissingPermissionError();
mPermissionDenied = false;



/**
* Displays a dialog with error message explaining that the location permission is missing.
*/
private void showMissingPermissionError()
PermissionUtils.PermissionDeniedDialog
.newInstance(true).show(getSupportFragmentManager(), "dialog");





2 Answers
2



Do you had set uses permission in manifest? If don't, you should set it first.


<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>



PermissionUtils is a class defined by the sample project. If you want to use it, you'll have to copy it to your project.


PermissionUtils





Thanks, it worked!
– Shahil Islam
Aug 17 at 9:14






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard