| | |
| | | |
| | | |
| | | import java.io.File; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | |
| | | return; |
| | | } |
| | | String type = getKeyValue("type", data);//小类 |
| | | String mode_type = "大类->" + topic + "--->小类->" + type;//用来打印的 |
| | | String mode_type = "大类->" + topic + "--->" + "小类->" + type;//用来打印的 |
| | | HdlLogLogic.print("uni--->发送--->" + mode_type + "\r\n" + data, true); |
| | | if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(topic)) { |
| | | //住宅模块 |
| | | switch (type) { |
| | |
| | | } |
| | | } |
| | | } |
| | | HdlLogLogic.print("uni--->发送--->" + mode_type + "\r\n" + data, true); |
| | | |
| | | } catch (Exception e) { |
| | | HdlLogLogic.print("uni--->发送--->" + e.getMessage(), true); |
| | | } |
| | |
| | | * 获取位置信息,包括经纬度 |
| | | */ |
| | | private void uniGetLocationInfo(String type, Object data, DCUniMPJSCallback callback) { |
| | | |
| | | |
| | | // 初始化LocationManager对象 |
| | | LocationManager locationManager = (LocationManager) HDLApp.getInstance().getSystemService(Context.LOCATION_SERVICE); |
| | | Geolocation geolocation = new Geolocation(); |
| | | //INTERNET 允许使用网络 |
| | | //ACCESS_FINE_LOCATION 允许使用GPS定位 |
| | | //ACCESS_COARSE_LOCATION 允许使用WIFI热点或基站来获取粗略的定位 |
| | | if (ActivityCompat.checkSelfPermission(HDLApp.getInstance(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(HDLApp.getInstance(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { |
| | | geolocation.setResult(-2); |
| | | geolocation.setDes(HDLApp.getInstance().getString(R.string.exception_no_location_information_permission)); |
| | | try { |
| | | // 初始化LocationManager对象 |
| | | LocationManager locationManager = (LocationManager) HDLApp.getInstance().getSystemService(Context.LOCATION_SERVICE); |
| | | Geolocation geolocation = new Geolocation(); |
| | | //INTERNET 允许使用网络 |
| | | //ACCESS_FINE_LOCATION 允许使用GPS定位 |
| | | //ACCESS_COARSE_LOCATION 允许使用WIFI热点或基站来获取粗略的定位 |
| | | if (ActivityCompat.checkSelfPermission(HDLApp.getInstance(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(HDLApp.getInstance(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { |
| | | geolocation.setResult(-2); |
| | | geolocation.setDes(HDLApp.getInstance().getString(R.string.exception_no_location_information_permission)); |
| | | uniCallbackData(type, geolocation, callback); |
| | | return; |
| | | } |
| | | // 判断设备是否支持定位功能 |
| | | if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { |
| | | geolocation.setResult(-1); |
| | | geolocation.setDes(HDLApp.getInstance().getString(R.string.exception_the_location_function_is_not_enabled)); |
| | | //todo 提示用户打开定位功能或者引导用户去系统设置页面打开定位功能 |
| | | uniCallbackData(type, geolocation, callback); |
| | | return; |
| | | } |
| | | Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); |
| | | if (location == null) { |
| | | geolocation.setResult(-3); |
| | | geolocation.setDes(HDLApp.getInstance().getString(R.string.exception_unable_location_move10_meters_later)); |
| | | uniCallbackData(type, geolocation, callback); |
| | | return; |
| | | } |
| | | geolocation.setResult(0); |
| | | geolocation.setDes(HDLApp.getInstance().getString(R.string.succeed)); |
| | | BigDecimal latitude = BigDecimal.valueOf(location.getLatitude());//经度 |
| | | BigDecimal longitude = BigDecimal.valueOf(location.getLongitude());//纬度 |
| | | double lat = latitude.setScale(6, RoundingMode.HALF_DOWN).doubleValue(); |
| | | double lon = longitude.setScale(6, RoundingMode.HALF_DOWN).doubleValue(); |
| | | geolocation.setLatitude(lat);//经度 |
| | | geolocation.setLongitude(lon);//纬度 |
| | | uniCallbackData(type, geolocation, callback); |
| | | return; |
| | | } |
| | | // 判断设备是否支持定位功能 |
| | | if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { |
| | | geolocation.setResult(-1); |
| | | geolocation.setDes(HDLApp.getInstance().getString(R.string.exception_the_location_function_is_not_enabled)); |
| | | //todo 提示用户打开定位功能或者引导用户去系统设置页面打开定位功能 |
| | | } catch (Exception e) { |
| | | Geolocation geolocation = new Geolocation(); |
| | | geolocation.setResult(-4); |
| | | geolocation.setDes(e.getMessage()); |
| | | uniCallbackData(type, geolocation, callback); |
| | | return; |
| | | } |
| | | Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); |
| | | if (location == null) { |
| | | geolocation.setResult(-3); |
| | | geolocation.setDes(HDLApp.getInstance().getString(R.string.exception_the_location_function_is_not_enabled)); |
| | | uniCallbackData(type, geolocation, callback); |
| | | return; |
| | | } |
| | | geolocation.setResult(0); |
| | | geolocation.setDes(HDLApp.getInstance().getString(R.string.succeed)); |
| | | geolocation.setLongitude(location.getLatitude());//纬度 |
| | | geolocation.setLatitude(location.getLongitude());//经度 |
| | | uniCallbackData(type, geolocation, callback); |
| | | HdlLogLogic.print("经纬度--->经度:" + location.getLongitude() + "纬度:" + location.getLatitude(), true); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | callback.invoke(getJSONObject(uniCallBackBaseBean)); |
| | | // callback.invoke(uniCallBackBaseBean); |
| | | HdlLogLogic.print("uni--->接收--->" + type + "--->" + new Gson().toJson(uniCallBackBaseBean), true); |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | HdlLogLogic.print("uni--->接收--->" + type + "--->" + e.getMessage(), false); |
| | | HdlLogLogic.print("uni--->接收--->" + type + "--->" + e.getMessage(), true); |
| | | } |
| | | |
| | | |