String peopleName = jsonObject.getJSONObject(“semantic”).getJSONObject(“slots”).getString(“name”);
String operationStr = jsonObject.getString(“operation”);
if (“CALL”.equals(operationStr)) {
String phoneNum = getContactNumberByName(peopleName);
String phoneCode = “”;
try {
phoneCode = jsonObject.getJSONObject(“semantic”).getJSONObject(“slots”).getString(“code”);
} catch (Exception e) {}
if (phoneNum != null & phoneNum.trim().length() > 0) {
String strAnswer = “正在打电话给:” + peopleName;
tvAnswer.setText(strAnswer);
startSpeak(strAnswer);
Uri uri = Uri.parse(“tel:” + phoneNum);
Intent intent = new Intent(Intent.ACTION_CALL, uri);
startActivity(intent);
} else if (phoneCode != null& phoneCode.trim().length() > 0) {
String strAnswer = “正在打电话给:” + peopleName;
tvAnswer.setText(strAnswer);
startSpeak(strAnswer);
Uri uri = Uri.parse(“tel:” + phoneCode);
Intent intent = new Intent(Intent.ACTION_CALL, uri);
startActivity(intent);
} else {
String phoneNumFromPinYin = getContactNumberByPinYin(PinYinUtil.convertAll(peopleName));
if (phoneNumFromPinYin != null& phoneNumFromPinYin.trim().length() > 0) {
String strAnswer = “正在打电话给:” + peopleName;
tvAnswer.setText(strAnswer);
startSpeak(strAnswer);
Uri uri = Uri.parse(“tel:” + phoneNumFromPinYin);
Intent intent = new Intent(Intent.ACTION_CALL, uri);
startActivity(intent);
} else {
String strAnswer = “通讯录中未找到:” + peopleName;
tvAnswer.setText(strAnswer);
startSpeak(strAnswer);
}
}
}
}
语音导航
这里不考虑”从A到B怎么走(A,B都为异地)“的情况。起点不是当前位置的情况解析方式相同,只是不常用。所以这里的例子起点默认为当前定位位置。
当我们说”导航到深圳北站“时,服务器返回的JSON如下:
{
“semantic”: {
“slots”: {
“endLoc”: {
“type”: “LOC_POI”,
“poi”: “深圳南站”,
“city”: “深圳市”,
“cityAddr”: “深圳”
},
“startLoc”: {
“type”: “LOC_POI”,
“city”: “CURRENT_CITY”,
“poi”: “CURRENT_POI”
}
}
},
“rc”: 0,
“operation”: “ROUTE”,
“service”: “map”,
“text”: “导航到深圳南站。”
}
首先我们对JSON进行解析:
if (“map”.equals(strService)) {
// operation": “ROUTE”
String endPoiStr = jsonObject.getJSONObject(“semantic”).getJSONObject(“slots”).getJSONObject(“endLoc”).getString(“poi”);
String endCityStr = jsonObject.getJSONObject(“semantic”).getJSONObject(“slots”).getJSONObject(“endLoc”).getString(“city”);
String endAddressStr = “”;
if (“CURRENT_CITY”.equals(endCityStr))
endCityStr = mSharedPreferences.getString(“cityName”, “未知”);
}
调用百度地图的导航接口,需要传入起始点的经纬度。当前位置的经纬度是已知的,所以要将目的地的字符串转成经纬度。这就涉及到百度LBS SDK的使用:
{
mEndSearch = GeoCoder.newInstance();
mEndSearch.setOnGetGeoCodeResultListener(new MyOnGetGeoCoderResultListener());
mEndSearch.geocode(new GeoCodeOption().city(endCityStr).address(endPoiStr));
}
class MyOnGetGeoCoderResultListener implements OnGetGeoCoderResultListener {
@Override
public void onGetGeoCodeResult(GeoCodeResult result) {
// TODO Auto-generated method stub
mEndLatLng = result.getLocation();
if (mEndLatLng != null) {
// 起始点:当前位置
startLat = Double.parseDouble(mSharedPreferences.getString(
“latitude”, “0.0”));
startLng = Double.parseDouble(mSharedPreferences.getString(
“longitude”, “0.0”));
// 目的地
endLat = mEndLatLng.latitude;
endLng = mEndLatLng.longitude;
LatLng startLatLng = new LatLng(startLat, startLng);
LatLng endLatLng = new LatLng(endLat, endLng);
// 构建 导航参数
NaviPara para = new NaviPara();
para.startPoint = startLatLng;
para.startName = “从这里开始”;
para.endPoint = endLatLng;
para.endName = “到这里结束”;
try {
BaiduMapNavigation.openBaiduMapNavi(para,
getApplicationContext());
} catch (BaiduMapAppNotSupportNaviException e) {
e.printStackTrace();
}
}
}
@Override
public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
}
}
语音启动应用
当我们说”打开百度地图“时,服务器返回的JSON是:
{
“semantic”: {
“slots”: {
“name”: “百度地图”
总结
可以看出,笔者的工作学习模式便是由以下 「六个要点」 组成:
❝ 多层次的工作/学习计划 + 番茄工作法 + 定额工作法 + 批处理 + 多任务并行 + 图层工作法❞
希望大家能将这些要点融入自己的工作学习当中,我相信一定会工作与学习地更富有成效。
下面是我学习用到的一些书籍学习导图,以及系统的学习资料。每一个知识点,都有对应的导图,学习的资料,视频,面试题目。
**如:我需要学习 **Flutter的知识。(大家可以参考我的学习方法)
- Flutter 的思维导图(无论学习什么,有学习路线都会事半功倍)
- Flutter进阶学习全套手册
- Flutter进阶学习全套视频
大概就上面这几个步骤,这样学习不仅高效,而且能系统的学习新的知识。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!
么,有学习路线都会事半功倍)**
[外链图片转存中…(img-DDKkCnPP-1714693962140)]
- Flutter进阶学习全套手册
[外链图片转存中…(img-NgcK4lTt-1714693962141)]
- Flutter进阶学习全套视频
[外链图片转存中…(img-DWiJyyRU-1714693962141)]
大概就上面这几个步骤,这样学习不仅高效,而且能系统的学习新的知识。
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!