hs_rohit
hs_rohit

Reputation: 103

Wrong 2nd argument type. Found: 'com.google.android.gms.location.LocationCallback', required: 'android.app.PendingIntent' more

I'm trying to use FusedLocationProviderClient in my program but i keep finding this error.

I'm getting the error in the requestLocationUpdates method

I'm following the tutorial from pubnub from here

My program is

public class DriverActivity extends AppCompatActivity {
private FusedLocationProviderClient mFusedLocationClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setInterval(5000);
    locationRequest.setFastestInterval(5000);
    locationRequest.setSmallestDisplacement(10);
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    mFusedLocationClient.requestLocationUpdates(locationRequest, new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) {
            Location location = locationResult.getLastLocation();
            Main2Activity.pubnub.publish()
                    .message("")
                    .channel("")
                    .async(new PNCallback<PNPublishResult>() {
                        @Override
                        public void onResponse(PNPublishResult result, PNStatus status) {
                            // handle publish result, status always present, result if successful
                            // status.isError() to see if error happened
                            if (!status.isError()) {
                                System.out.println("pub timetoken: " + result.getTimetoken());
                            }
                            System.out.println("pub status code: " + status.getStatusCode());
                        }
                    });
                    }

        });
    }

Upvotes: 1

Views: 158

Answers (1)

Reagan Yego
Reagan Yego

Reputation: 26

Add Looper.myLooper() as the third parameter in your requestLocationUpdates() method.

Upvotes: 1

Related Questions