Android RequestLocationUpdate与PendingEvent永不触发
我尝试每隔一段时间在后台运行一次位置检查,因此我尝试使用IntentService从FusedLocationApi获取位置更新。但悬挂式帐篷从不着火 代码:Android RequestLocationUpdate与PendingEvent永不触发,android,android-pendingintent,android-intentservice,fusedlocationproviderapi,Android,Android Pendingintent,Android Intentservice,Fusedlocationproviderapi,我尝试每隔一段时间在后台运行一次位置检查,因此我尝试使用IntentService从FusedLocationApi获取位置更新。但悬挂式帐篷从不着火 代码: 我遗漏了什么吗?您提供给requestLocationUpdates()的pendingent将触发广播Intent,因为您调用了pendingent.getBroadcast()。但是,您在pendingent中提供的类是服务。将getBroadcast()替换为getService()`。Am也有类似问题。我使用一个广播,它只被调用一
我遗漏了什么吗?您提供给
requestLocationUpdates()
的pendingent
将触发广播Intent
,因为您调用了pendingent.getBroadcast()
。但是,您在pendingent
中提供的类是服务
。将getBroadcast()替换为getService()`。Am也有类似问题。我使用一个广播,它只被调用一次,其中LocationResult LocationResult=LocationResult.extractResult(intent);返回null
,并且我的广播从不被触发again@philipoghenerobobalogun你可能想根据自己的情况提出一个新问题。这样的评论不太可能从社区得到任何帮助。我在这里问了一个新问题@DavidWasser如何根据需要更改locationRequestObjects值,假设我以“正常”速率开始,在一段时间(30秒)内,我希望它以实时“快速”速率。目前,当我尝试这样做时,我遇到了活套异常。@PedroVarela请打开一个新问题。在对另一个问题的评论中要求这种澄清不是使用这个平台的正确方式。其他有类似问题的人将无法找到答案。这也会让你得到更好的答案和更好的关注。
public class LocationIntentService extends IntentService
implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener
{
private static GoogleApiClient mApiClient;
...
@Override
public void onCreate() {
if (mApiClient == null) {
mApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mApiClient.connect();
}
}
...
@Override
public void onConnected(Bundle bundle) {
LocationRequest locationRequest = new LocationRequest();
locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
locationRequest.setInterval(Constants.LOCATION_UPDATE_INTERVAL_MILIS);
locationRequest.setFastestInterval(Constants.LOCATION_UPDATE_INTERVAL_MILIS / 2);
Intent locationIntent = new Intent(getApplicationContext(), LocationIntentService.class);
PendingIntent locationPendingIntent = PendingIntent.getBroadcast(
getApplicationContext(),
0,
locationIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
LocationServices.FusedLocationApi
.requestLocationUpdates(mApiClient, locationRequest,locationPendingIntent);
...
}
...
}