我正在尝试获取位置更新信息.为此,我创建了一个服务,在服务类的onStartCommand中我正在创建GoogleApiClient,但我没有在服务中获得连接回调.请帮忙解决这个问题.
下面给出的是服务代码和活动我已经使用startService方法启动了服务:
startService(new Intent(this, LocationService.class));
Run Code Online (Sandbox Code Playgroud)
服务代码
public class LocationService extends Service implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, LocationListener {
private GoogleApiClient mLocationClient;
private Location mCurrentLocation;
LocationRequest mLocationRequest;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO do something useful
Toast.makeText(this, "onStartCommand", Toast.LENGTH_SHORT).show();
mLocationClient = new GoogleApiClient.Builder(LocationService.this)
.addApi(LocationServices.API).addConnectionCallbacks(LocationService.this)
.addOnConnectionFailedListener(LocationService.this).build();
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setFastestInterval(1000);
return Service.START_NOT_STICKY;
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
mCurrentLocation = location;
Toast.makeText(this, mCurrentLocation.getLatitude() +", "+ mCurrentLocation.getLatitude(), Toast.LENGTH_SHORT).show();
}
@Override …Run Code Online (Sandbox Code Playgroud) 为了满足谷歌最近的跟踪软件政策,如果应用程序使用应用程序收集某些敏感用户数据,开发人员需要添加 isMonitoringTool 标志。有人可以帮我在清单中定义这个标志吗?
这是他们提到这样做的文档, https://support.google.com/googleplay/android-developer/answer/12253906#stalkerware_preview
提前致谢。