Scroll Essential Android 2.3 Manual de usuario Pagina 42

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 47
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 41
Android Wear Docs, Release 1.1
dependencies {
compile ’com.google.android.support:wearable:1.1.0’
compile ’com.google.android.gms:play-services-wearable:6.5.+’
compile ’com.google.android.gms:play-services-location:6.5.+’
}
8.1.2 Add a Location Listener
1. Build a Google Play Services client that includes the LocationServices API.
public class WearableActivity extends Activity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener
LocationListener {
GoogleApiClient googleClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_handheld);
// Build a new GoogleApiClient
googleClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
// Location listener implementation (Step 2)
...
}
2. Register a location listener for the Fused Location API.
// Connect to Google Play Services when the Activity starts
@Override
protected void onStart() {
super.onStart();
googleClient.connect();
}
// Register as a listener when connected
@Override
public void onConnected(Bundle connectionHint) {
// Create the LocationRequest object
LocationRequest locationRequest = LocationRequest.create();
// Use high accuracy
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
// Set the update interval to 2 seconds
locationRequest.setInterval(TimeUnit.SECONDS.toMillis(2));
// Set the fastest update interval to 2 seconds
locationRequest.setFastestInterval(TimeUnit.SECONDS.toMillis(2));
// Set the minimum displacement
locationRequest.setSmallestDisplacement(2);
38 Chapter 8. Wearable GPS
Vista de pagina 41
1 2 ... 37 38 39 40 41 42 43 44 45 46 47

Comentarios a estos manuales

Sin comentarios