最近我用于Fused Location API
定位目的。在应用 google play 服务库之前com.google.android.gms:play-services:8.3.0
,应用程序大小为4.3MB
(4,499,239 字节),但在使用此 api 后,它增加到5.8 MB
(6,085,932 字节)。项目中只添加了一个类。即LocationService.java
我从服务类调用它,这里是代码。
定位服务.java
public class LocationServiceRACE implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
public LocationServiceRACE(Context serviceContext) {
mGoogleApiClient = new GoogleApiClient.Builder(serviceContext)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
public GoogleApiClient getmGoogleApiClient() {
return this.mGoogleApiClient;
}
@Override
public void onConnected(Bundle bundle) {
if (mGoogleApiClient.isConnected())
startLocationUpdates();
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
protected void startLocationUpdates() {
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
mLocationRequest.setInterval(60000); // Update location every 60 second
mLocationRequest.setSmallestDisplacement(100);
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
}
除了 Fused Location 之外,我没有使用其他 api,并且在添加 google play 服务后,ProGuard 中没有添加/更改任何内容。如何减少我只需要fused location
api 的应用程序大小?