小编Fli*_*bor的帖子

位置设置对话框显示两次或如何检测该对话框显示\已关闭

我想在onResume()中每次关闭前景和位置中的活动时显示位置设置对话框.

问题:每次都会创建新的设置对话框,而不会破坏前一个,我从对话中堆叠.通过后退按钮或取消按钮将显示之前显示的另一个设置对话框.

另一个问题,如果从通知栏对话框启用位置仍然显示,我无法关闭它.

public class CheckLocationActivity extends FloatingActionsMenuActivity implements ConnectionCallbacks, OnConnectionFailedListener {

    private GoogleApiClient googleApiClient;

    @Override
    public void onResume() {
        super.onResume();
        showDialog();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    private void showDialog() {
        if (googleApiClient == null) {
            googleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(LocationServices.API)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this).build();
            googleApiClient.connect();


            LocationRequest locationRequest = LocationRequest.create();
            locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
            locationRequest.setInterval(30 * 1000);
            locationRequest.setFastestInterval(5 * 1000);
            LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
                    .addLocationRequest(locationRequest);

            //**************************
//            builder.setAlwaysShow(true); //this is the key ingredient
            //**************************


            PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
            result.setResultCallback(new …
Run Code Online (Sandbox Code Playgroud)

android locationmanager google-play-services

5
推荐指数
1
解决办法
886
查看次数