Search code examples
javaandroidlocationandroid-geofence

Geofences - addOnCompleteListener(this) not working


I am trying to build a geofencing app. I found a sample on GitHub and referenced that for the majority of my project. If it is of any significance, this code was included in the MainActivity in the sample, but I have it in another activity.

On the addGeofences method, I get an error that says:

addOnCompleteListener (com.google.android.gms.tasks.OnCompleteListener) in Task cannot be applied to (my package name)

I have scoured posts and almost all are about Firebase. Any help is appreciated. Thanks!

Here is the code:

 @SuppressWarnings("MissingPermission")
private void addGeofences() {
    if (!checkPermissions()) {
        showSnackbar(getString(R.string.insufficient_permissions));
        return;
    }

    mGeofencingClient.addGeofences(getGeofencingRequest(), getGeofencePendingIntent())
            .addOnCompleteListener(this);
}

Note: I also get the same error in the removeGeofences method.


Solution

  • I figured out this problem...I forgot to implement the OnCompleteListener<Void> in the class declaration. The corrected code looks like this:

    public class MainActivity extends AppCompatActivity implements OnCompleteListener<Void>{