我的应用正在尝试访问设备的位置,我在以下内容中包含以下内容AndroidManifest.xml
:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application>
<meta-data android:name="com.google.android.gms.version" />
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
我已实现GoogleApiClient.ConnectionCallbacks
如下访问位置服务:
public class BackgroundLocationService implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private static final String TAG = BackgroundLocationService.class.getSimpleName();
private static GoogleApiClient googleApiClient;
private static PendingIntent locationCallback;
public static int LOCATION_INTERVAL = 10000;
public static int FAST_INTERVAL = 5000;
@Override
public void onConnected(Bundle bundle) {
Log.i(TAG, "Connected to Google API");
LocationRequest request = new LocationRequest();
request.setInterval(LOCATION_INTERVAL);
request.setFastestInterval(FAST_INTERVAL);
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, locationCallback);
}
@Override
public …
Run Code Online (Sandbox Code Playgroud)