【发布时间】:2017-05-21 07:58:41
【问题描述】:
我正在使用谷歌功能为用户启用和禁用位置,我的主要目标是,我输入相机活动并询问用户是否单击取消它会返回上一个活动,如果一切正常的话用户拍照。
这是我的代码:
`public class GoogleLocation extends Activity {
private static final int REQUEST_CHECK_SETTINGS = 5 ;
public static void displayLocationSettingsRequest(final Context context) {
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context)
.addApi(LocationServices.API).build();
googleApiClient.connect();
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(10000);
locationRequest.setFastestInterval(10000 / 2);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
builder.setAlwaysShow(true);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
Log.i("location", "All location settings are satisfied.");
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
Log.i("location", "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().
Log.d("HELLO2","HELLO2");
status.startResolutionForResult((Activity) context, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
Log.i("location", "PendingIntent unable to execute request.");
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
Log.i("location", "Location settings are inadequate, and cannot be fixed here. Dialog not created.");
break;
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("requestCode",String.valueOf(requestCode));
Log.d("resultCode",String.valueOf(resultCode));
if (requestCode == REQUEST_CHECK_SETTINGS) {
Log.d("ENTERED","ENTERED");
if(resultCode == RESULT_OK){
}
if(resultCode == RESULT_CANCELED){
Log.d("ENTERED","ENTERED");
this.finish();
}
}
}
} ` 我认为我可以使用 onactivityresult 控制对话框选项“ok”和“cancel”,但是正如你们在 onactivity 结果中看到的那样,我有 2 Log.d 这只是在我按下相机上的“x”时被触发关闭相机,这是怎么回事?我需要控制对话框,但它不起作用:/。
有什么建议吗?
谢谢
【问题讨论】:
标签: java android android-studio localization geolocation