Skip to content

Instantly share code, notes, and snippets.

@TheOpenDevProject
Created February 5, 2017 08:53
Show Gist options
  • Save TheOpenDevProject/26b5e5a8a47729f8e92fa9e2931c6be4 to your computer and use it in GitHub Desktop.
Save TheOpenDevProject/26b5e5a8a47729f8e92fa9e2931c6be4 to your computer and use it in GitHub Desktop.
public class DebugScreen extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
private GoogleApiClient googleApiClient;
private LocationRequest locationRequest;
private FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_debug_screen);
Button wpBttn = (Button) findViewById(R.id.wpNtfy);
googleApiClient = new GoogleApiClient.Builder(DebugScreen.this)
.addApi(LocationServices.API)
.addConnectionCallbacks(DebugScreen.this)
.addOnConnectionFailedListener(DebugScreen.this)
.build();
googleApiClient.connect();
locationRequest = new LocationRequest();
locationRequest.setInterval(1000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
@Override
public void onConnected(@Nullable Bundle bundle) {
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
fusedLocationProviderApi.requestLocationUpdates(googleApiClient, locationRequest, this);
return;
}
fusedLocationProviderApi.getLastLocation(googleApiClient);
Log.d("GPS Connected","Location Services API Connected");
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
@Override
public void onLocationChanged(Location location) {
Log.d("Location Changed",String.valueOf(location.getLatitude()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment