uniapp 检测android 是否开启GPS功能
作者:互联网
/**检查是否打开GPS功能(android)**/ export const checkOpenGPSServiceByAndroid = () => { let system = uni.getSystemInfoSync();// 获取系统信息 if (system.platform === 'android') { // 判断平台 var context = plus.android.importClass("android.content.Context"); var locationManager = plus.android.importClass("android.location.LocationManager"); var main = plus.android.runtimeMainActivity(); var mainSvr = main.getSystemService(context.LOCATION_SERVICE); if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) { uni.showModal({ title: '提示', content: '请打开定位服务功能', showCancel: false, // 不显示取消按钮 success() { if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) { var Intent = plus.android.importClass('android.content.Intent'); var Settings = plus.android.importClass('android.provider.Settings'); var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); main.startActivity(intent); // 打开系统设置GPS服务页面 } else { console.log('GPS功能已开启'); } } }); } } }
标签:uniapp,mainSvr,plus,importClass,var,android,GPS 来源: https://www.cnblogs.com/Leesttee/p/10598671.html