繁体   English   中英

检查 android 设备中的位置服务是否启用

[英]to check location service enable or not in android device

很抱歉问这个问题,但我不是 android 应用程序的开发人员。 我想问一下是否可以对自定义地理定位 android 应用程序进行编码,以便当用户启动应用程序并检测到设备的位置服务已关闭时,它将显示为提示,或者应用程序在位置服务之前不会继续进行是否由用户手动开启?

我们正在使用移动设备管理 (mdm) 来管理 android 移动设备,但 mdm 没有强制执行位置服务设置的能力。

自定义地理位置 android 应用程序需要启用位置服务才能正常工作。

您可以检查 GPS 是否启用,如果未启用则显示消息

        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

            //here do what you want when the GPS service is enabled

            Toast.makeText(MainActivity.this, "is enable", Toast.LENGTH_SHORT).show();

        } else {

            MaterialAlertDialogBuilder locationDialog = new MaterialAlertDialogBuilder(MainActivity.this);
            locationDialog.setTitle("Attention");
            locationDialog.setMessage("Location settings must be enabled from the settings to use the application");
            locationDialog.setCancelable(false);
            locationDialog.setPositiveButton("Open settings", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    startActivity(intent);
                }
            });
            locationDialog.create().show();
        }

    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM