- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
7 天以来,我一直在尝试这样做,但没有结果。问题是 ResultCallback,对于地理围栏我需要 ResultCallback,而对于 LocationSettings 我需要 ResultCallback,有没有办法做到这一点?我很欣赏一些提示...我正在使用最新的 Google Play Services 7.0感谢您的支持:)
public class GeofenceIntentService
extends IntentService
implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
ResultCallback<Status>, ResultCallback<LocationSettingsResult> {
// onResult for geofencing
public void onResult(Status status) {
Log.i(TAG, "onResult");
if (status.isSuccess()) {
Log.i(TAG, "status.isSuccess()");
} else {
String errorMessage = GeofenceErrorMessages.getErrorString(getApplicationContext(),
status.getStatusCode());
Log.e(TAG, errorMessage);
}
}
// onResult for LocationSettings
@Override
public void onResult(LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
Log.i(TAG, "All location settings are satisfied.");
startLocationUpdates();
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
Log.i(TAG, "Location settings are not satisfied. Show the user a dialog to" +
"upgrade location settings ");
try {
// Show the dialog by calling startResolutionForResult(), and check the result
// in onActivityResult().
status.startResolutionForResult(BaseActivity.this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
Log.i(TAG, "PendingIntent unable to execute request.");
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
Log.i(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog " +
"not created.");
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
// Check for the integer request code originally supplied to startResolutionForResult().
case REQUEST_CHECK_SETTINGS:
switch (resultCode) {
case Activity.RESULT_OK:
Log.i(TAG, "User agreed to make required location settings changes.");
startLocationUpdates();
break;
case Activity.RESULT_CANCELED:
Log.i(TAG, "User chose not to make required location settings changes.");
break;
}
break;
}
}
}
最佳答案
I had the same problem and this is what I did
类定义:
public class Activity/Service extends AppCompatActivity/IntentService implements
ConnectionCallbacks,
OnConnectionFailedListener,
ResultCallback<Status> {
...
}
对于 GeofencingApi:
public void addGeofencesButtonHandler(View view) {
if (!mGoogleApiClient.isConnected()) {
// Log.e(TAG, "Not connected");
return;
}
try {
PendingResult<Status> result =
LocationServices.GeofencingApi.addGeofences(
mGoogleApiClient,
getGeofencingRequest(),
getGeofencePendingIntent()
);
result.setResultCallback(this);
} catch (SecurityException securityException) {
logSecurityException(securityException);
}
}
对于 SettingsApi:
Used chaining to setResultCallback
protected void checkLocationSettings() {
LocationServices.SettingsApi.checkLocationSettings(
mGoogleApiClient,
mLocationSettingsRequest
).setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
Log.i(TAG, "All location settings are satisfied.");
if (!mRequestingLocationUpdates) {
mRequestingLocationUpdates = true;
setButtonsEnabledState();
startLocationUpdates();
}
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
Log.i(TAG, "Location settings are not satisfied. Show the user a dialog to" +
"upgrade location settings ");
try {
status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
Log.i(TAG, "PendingIntent unable to execute request.");
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
Log.i(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog " +
"not created.");
break;
}
}
});
}
关于Android 新的 LocationSettings 和 Geofencing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29931551/
我正在使用谷歌播放服务。对于我的应用程序,位置是关键组件。当 GPS 关闭时,我使用 LocationSettingsClient 向用户显示一个对话框以启用它。问题是,在按下 OK 后,某些设备上再
我想每隔几分钟在后台更新一次用户的位置。 我使用了这个示例代码 googlesamples/android-play-location 但将其更改为与 Service 一起使用 public clas
7 天以来,我一直在尝试这样做,但没有结果。问题是 ResultCallback,对于地理围栏我需要 ResultCallback,而对于 LocationSettings 我需要 ResultCal
val request = LocationRequest() request.interval = 1000 * 60 request.fastestInterval = 1000
我是一名优秀的程序员,十分优秀!