我正在构建一个应用程序,我必须不断保存用户的位置,然后将其发送到服务器.为此,我在服务中使用FusedLocationApis.我第一次要求用户打开位置.它工作得很好.
现在,如果用户无意中关闭了该位置该怎么办.我该如何通知他?开发人员必须处理这个问题,还是只留给用户?
我想给他一个android通知.为此,我需要不断检查我们在服务中启用的位置.我有一个工作代码(函数checkHighAccuracyLocationMode).但是我应该在哪里检查(checkHighAccuracyLocationMode)?每次在此服务中启动哪个功能?或者,无论如何,当用户关闭他的位置时,我可以获得一个功能?
这是我的服务:
public class locationUpdatesService extends Service implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
private Location mLastLocation;
private Location mCurrentLocation;
private String mLastUpdateTime;
private dataBaseHandler db_helper;
@Override
public int onStartCommand(Intent intent, int flags, int startId){
initialise();
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onCreate() {
super.onCreate();
db_helper = new dataBaseHandler(getApplicationContext(),dataBaseHandler.DATABASE_NAME,null,1);
}
@Override
public void onDestroy() {
stopLocationUpdates();
singletGoogleClientApi.setinstancenull();
singletLocationRequest.setinstancenull();
super.onDestroy();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
private void initialise(){
Log.e("ghgdhu","qaws");
if (singletGoogleClientApi.getinstance().getGoogleApiCLient() == null) …Run Code Online (Sandbox Code Playgroud)