Oreo没有从Schedule Job调用onLocationChanged方法

时间:2018-05-31 11:20:26

标签: android performance android-location android-8.0-oreo android-jobscheduler

即使应用程序处于后台,我也会从location service调用JobSchedular来使其正常工作。

这是我安排LocationService

的方式
JobInfo jobInfo;
JobScheduler jobScheduler;

ComponentName componentName= new ComponentName(this, LocationUpdateService.class);
JobInfo.Builder builder= new JobInfo.Builder(11, componentName);

builder.setPeriodic(900000);
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
builder.setPersisted(true);

jobInfo= builder.build();
jobScheduler= (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);


jobScheduler.schedule(jobInfo);

现在它调用LocationUpdateService,并执行onCreate()onStartJob方法,但不会在onLocationChanged()中执行oreo。这在Nougatlollipop设备

上完全正常

将用户位置发送到服务的所有逻辑都在onLocationChanged(),如果我将逻辑放在onStartJob()中,我无法获得用户{{} 1}}。

lat/lng

我也尝试过在public class LocationUpdateService extends JobService implements LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, IServiceResponse { @Override public void onCreate() { super.onCreate(); Log.i(TAG, "onCreateCalled: "); if (isGooglePlayServicesAvailable()) { mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); mGoogleApiClient.connect(); } } @Override public boolean onStartJob(JobParameters params) { Log.i(TAG, "onStartCommand: "); return true; } @Override public boolean onStopJob(JobParameters params) { Log.d("JobStopped", "JobStopped"); return true; } @Override public void onLocationChanged(Location location) { } 中获取用户的lat/lng,但它返回了我(0,0)onStartJob

lat/lng

我正在使用Location location= new Location(""); location.getLongitude() 版本play-services

0 个答案:

没有答案