百度地图sdk导航
文章目录
- 百度地图sdk导航
- 前言
- 一、准备
- 二、下载demo
- 三、配置
- 将上面libs的复制到下面的目录(我有x86和x86_64因为之前同事写了地图插件🐓)
- 导入这两个aar
- 导入过程
- 1.配置build.gradle(两个不同的)
- 2.打开apk试玩
- 看源码找到需要的demo界面(我:专业导航)(已改好)
- 控制界面调用(只复制了方法)
- 创建(复制)xml界面
- 配置android界面
- 获取TTS服务 appid等
- 打开网址
- 进入控制台
- 点击语音技术
- 创建应用
- 应用名称、应用描述随便填,包名填上面gradle中的 applicationId
- 创建完毕后如下,复制后填入即可
- 效果
- 总结
前言
公司要用到百度地图sdk的专业导航,让写个flutter插件。。。。
我负责android原生导航😁
在此记录
提示:以下是本篇文章正文内容,下面案例可供参考
一、准备
官方文档
https://lbsyun.baidu.com/index.php?title=android-navsdk/guide/projectConfiguration
根据文档配置权限,配置ak
二、下载demo
点击相关下载
把下面这两个都下载下来
解压
三、配置
将上面libs的复制到下面的目录(我有x86和x86_64因为之前同事写了地图插件🐓)
导入这两个aar
导入过程
然后finish
1.配置build.gradle(两个不同的)
代码如下(示例):
android {compileSdkVersion 29defaultConfig {minSdkVersion 16}lintOptions {disable 'InvalidPackage'}sourceSets {main {//我加入的-------jniLibs.srcDir 'libs'//------------}}
}dependencies {implementation files('libs/BaiduLBS_Android.jar')implementation files('libs/okio-1.13.0.jar')implementation files('libs/okhttp-3.8.1.jar')implementation files('libs/bos-android-sdk-1.0.3.jar')implementation files('libs/BaiduTraceSDK_v3_1_7.jar')implementation files('libs/intellij_annotations.jar')implementation files('libs/javapoet-1.9.0.jar')implementation files('libs/protobuf-java-2.3.0-micro.jar')implementation files('libs/protobuf_gens-map.jar')implementation project(':onsdk_all')//我加入的-------implementation 'com.android.support:appcompat-v7:28.0.0'implementation 'com.android.support:cardview-v7:28.0.0'implementation 'com.android.support:recyclerview-v7:28.0.0'implementation 'com.android.support.constraint:constraint-layout:1.1.3'//----------implementation project(':NaviTts')
}
android {compileSdkVersion 29lintOptions {disable 'InvalidPackage'}defaultConfig {// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).applicationId "com.dyys.baidumap.plugin.flutter_baidumap_plugin_example"minSdkVersion 18targetSdkVersion 29versionCode flutterVersionCode.toInteger()versionName flutterVersionName//我加入的----------------// 避免"64K 引用限制"multiDexEnabled true// 导航SDK内部使用了annotationProcessor,需要添加下面代码,防止编译异常javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true }}//-----------------------------}buildTypes {release {// TODO: Add your own signing config for the release build.// Signing with the debug keys for now, so `flutter run --release` works.signingConfig signingConfigs.debug}}
2.打开apk试玩
看源码找到需要的demo界面(我:专业导航)(已改好)
DemoGuideActivity.java
/** Copyright (C) 2018 Baidu, Inc. All Rights Reserved.*/
package com.dyys.baidumap.plugin.flutter_baidumap_plugin.activity;import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;import com.baidu.navisdk.adapter.BNaviCommonParams;
import com.baidu.navisdk.adapter.BaiduNaviManagerFactory;
import com.baidu.navisdk.adapter.IBNRouteGuideManager;
import com.baidu.navisdk.adapter.IBNTTSManager;
import com.baidu.navisdk.adapter.IBNaviListener;
import com.baidu.navisdk.adapter.IBNaviViewListener;
import com.baidu.navisdk.adapter.struct.BNGuideConfig;
import com.baidu.navisdk.adapter.struct.BNHighwayInfo;
import com.baidu.navisdk.adapter.struct.BNRoadCondition;
import com.baidu.navisdk.adapter.struct.BNaviInfo;
import com.baidu.navisdk.adapter.struct.BNaviLocation;
import com.baidu.navisdk.ui.routeguide.model.RGLineItem;import java.util.List;/*** 诱导界面*/
public class DemoGuideActivity extends Activity {private static final String TAG = "flutter_baidumap_plugin";private IBNRouteGuideManager mRouteGuideManager;private IBNaviListener.DayNightMode mMode = IBNaviListener.DayNightMode.DAY;View view;GuidePop guidePop;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);boolean fullScreen = supportFullScreen();Bundle params = new Bundle();params.putBoolean(BNaviCommonParams.ProGuideKey.IS_SUPPORT_FULL_SCREEN, fullScreen);mRouteGuideManager = BaiduNaviManagerFactory.getRouteGuideManager();BNGuideConfig config = new BNGuideConfig.Builder().params(params).build();view = mRouteGuideManager.onCreate(this, config);if (view != null) {setContentView(view);}guidePop = new GuidePop(this);initTTSListener();routeGuideEvent();}// 导航过程事件监听private void routeGuideEvent() {BaiduNaviManagerFactory.getRouteGuideManager().setNaviListener(new IBNaviListener() {@Overridepublic void onRoadNameUpdate(String name) { // 弹窗展示
// ControlBoardWindow.getInstance().showControl("当前路名更新——" + name);guidePop.setdata(name);}@Overridepublic void onRemainInfoUpdate(int remainDistance, int remainTime) { // 弹窗展示
// ControlBoardWindow.getInstance()
// .showControl("距离目的地的剩余——" + remainDistance + "m " + remainTime + "s");guidePop.setdata(remainDistance, remainTime);}@Overridepublic void onViaListRemainInfoUpdate(Message msg) {}@Overridepublic void onGuideInfoUpdate(BNaviInfo naviInfo) { // 弹窗展示
// ControlBoardWindow.getInstance().showControl("诱导信息——" + naviInfo.toString());guidePop.setdata(naviInfo);}@Overridepublic void onHighWayInfoUpdate(Action action, BNHighwayInfo info) {
// ControlBoardWindow.getInstance()
// .showControl("高速信息——" + action + " " + info.toString());}@Overridepublic void onFastExitWayInfoUpdate(Action action, String name, int dist, String id) {
// ControlBoardWindow.getInstance()
// .showControl("快速路出口信息——" + action + " " + name + " 出口还有" + dist + "米");}@Overridepublic void onEnlargeMapUpdate(Action action, View enlargeMap, String remainDistance,int progress, String roadName, Bitmap turnIcon) {
// ControlBoardWindow.getInstance().showControl("放大图回调信息——不想写了自己看吧_gb");}@Overridepublic void onDayNightChanged(DayNightMode style) {
// ControlBoardWindow.getInstance().showControl("日夜更替信息回调" + style);}@Overridepublic void onRoadConditionInfoUpdate(double progress, List<BNRoadCondition> items) {
// ControlBoardWindow.getInstance().showControl("路况信息更新 进度:" + progress + " 路况:。。。");}@Overridepublic void onMainSideBridgeUpdate(int type) {
// ControlBoardWindow.getInstance().showControl("主辅路、高架桥信息更新:" + type + " 意义不明??—gb");}@Overridepublic void onLaneInfoUpdate(Action action, List<RGLineItem> laneItems) {
// if (laneItems != null && laneItems.size() > 0) {
// ControlBoardWindow.getInstance().showControl("车道线信息更新:" +
// action + laneItems.get(0).toString() + " ...");
// }}@Overridepublic void onSpeedUpdate(String speed, boolean isOverSpeed) {
// ControlBoardWindow.getInstance()
// .showControl("当前车速:" + speed + " 是否超速:" + isOverSpeed);}@Overridepublic void onArriveDestination() {
// BNaviResultInfo info =
// BaiduNaviManagerFactory.getRouteGuideManager().getNaviResultInfo();
// Toast.makeText(DemoGuideActivity.this, "导航结算数据: " + info.toString(),
// Toast.LENGTH_SHORT).show();
// ControlBoardWindow.getInstance().showControl("抵达目的地:" + info.toString());}@Overridepublic void onArrivedWayPoint(int index) {
// ControlBoardWindow.getInstance().showControl("到达途径点——" + index);}@Overridepublic void onLocationChange(BNaviLocation naviLocation) {
// ControlBoardWindow.getInstance().showControl("GPS位置有更新时的回调:");}@Overridepublic void onMapStateChange(MapStateMode mapStateMode) {// if (mapStateMode == MapStateMode.BROWSE) {// Toast.makeText(DemoGuideActivity.this, "操作态", Toast// .LENGTH_SHORT).show();// } else if (mapStateMode == MapStateMode.NAVING) {// Toast.makeText(DemoGuideActivity.this, "导航态", Toast// .LENGTH_SHORT).show();// }
// ControlBoardWindow.getInstance()
// .showControlOnlyone("底图操作态和导航态的回调: 别老摸就不会老回调了_为什么不自动变回导航态?_gb",
// "onMapStateChange");}@Overridepublic void onStartYawing(String s) {}@Overridepublic void onYawingSuccess() {
// ControlBoardWindow.getInstance().showControl("偏航成功的回调");}@Overridepublic void onYawingArriveViaPoint(int i) {}@Overridepublic void onNotificationShow(String msg) {Log.e(TAG, msg);
// ControlBoardWindow.getInstance().showControl("导航中通知型消息的回调" + msg);}@Override public void onHeavyTraffic() {Log.e(TAG, "onHeavyTraffic");
// ControlBoardWindow.getInstance().showControl("导航中前方一公里出现严重拥堵的回调");}@Overridepublic void onNaviGuideEnd() {DemoGuideActivity.this.finish();}});BaiduNaviManagerFactory.getRouteGuideManager().setNaviViewListener(new IBNaviViewListener() {@Overridepublic void onMainInfoPanCLick() {
// ControlBoardWindow.getInstance().showControl("诱导面板的点击");guidePop.showAtLocation(view,Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);}@Overridepublic void onNaviTurnClick() {
// ControlBoardWindow.getInstance().showControl("界面左上角转向操作的点击");}@Overridepublic void onFullViewButtonClick(boolean show) {
// ControlBoardWindow.getInstance().showControl("全览按钮的点击");}@Overridepublic void onFullViewWindowClick(boolean show) {
// ControlBoardWindow.getInstance().showControl("全览小窗口的点击");}@Overridepublic void onNaviBackClick() {Log.e(TAG, "onNaviBackClick");
// ControlBoardWindow.getInstance().showControl("导航页面左下角退出按钮点击");}@Overridepublic void onBottomBarClick(Action action) {
// ControlBoardWindow.getInstance().showControl("底部中间部分点击");}@Overridepublic void onNaviSettingClick() {Log.e(TAG, "onNaviSettingClick");
// ControlBoardWindow.getInstance().showControl("底部右边更多设置按钮点击");}@Overridepublic void onRefreshBtnClick() {
// ControlBoardWindow.getInstance().showControl("刷新按钮");}@Overridepublic void onZoomLevelChange(int level) {
// ControlBoardWindow.getInstance().showControl("地图缩放等级:" + level);}@Overridepublic void onMapClicked(double x, double y) {
// ControlBoardWindow.getInstance().showControlOnlyone("地图点击的回调(国测局GCJ02坐标):x="
// + x + " y=" + y, "onMapClicked");}@Overridepublic void onMapMoved() {Log.e(TAG, "onMapMoved");
// ControlBoardWindow.getInstance().showControl("移动地图的回调");}@Overridepublic void onFloatViewClicked() {
// ControlBoardWindow.getInstance().showControl("后台诱导悬浮窗的点击");
// try {
// Intent intent = new Intent();
// intent.setPackage(getPackageName());
// intent.setClass(DemoGuideActivity.this,
// Class.forName(DemoGuideActivity.class.getName()));
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
// | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
// startActivity(intent);
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// }}});}private void initTTSListener() {// 注册同步内置tts状态回调BaiduNaviManagerFactory.getTTSManager().setOnTTSStateChangedListener(new IBNTTSManager.IOnTTSPlayStateChangedListener() {@Overridepublic void onPlayStart() {Log.e("BNSDKDemo", "ttsCallback.onPlayStart");
// ControlBoardWindow.getInstance().showControl("ttsCallback.onPlayStart");}@Overridepublic void onPlayEnd(String speechId) {Log.e("BNSDKDemo", "ttsCallback.onPlayEnd");
// ControlBoardWindow.getInstance().showControl("ttsCallback.onPlayEnd");}@Overridepublic void onPlayError(int code, String message) {Log.e("BNSDKDemo", "ttsCallback.onPlayError");
// ControlBoardWindow.getInstance().showControl("ttsCallback.onPlayError");}});// 注册内置tts 异步状态消息BaiduNaviManagerFactory.getTTSManager().setOnTTSStateChangedHandler(new Handler(Looper.getMainLooper()) {@Overridepublic void handleMessage(Message msg) {Log.e("BNSDKDemo", "ttsHandler.msg.what=" + msg.what);
// ControlBoardWindow.getInstance()
// .showControl("ttsHandler.msg.what=" + msg.what);}});}private void unInitTTSListener() {BaiduNaviManagerFactory.getTTSManager().setOnTTSStateChangedListener(null);BaiduNaviManagerFactory.getTTSManager().setOnTTSStateChangedHandler(null);}@Overrideprotected void onStart() {super.onStart();
// if (BNDemoUtils.getBoolean(this, "float_window")) {
// mRouteGuideManager.onForeground();
// }mRouteGuideManager.onStart();}@Overrideprotected void onResume() {super.onResume();getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);mRouteGuideManager.onResume();}protected void onPause() {super.onPause();mRouteGuideManager.onPause();getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);}@Overrideprotected void onStop() {super.onStop();mRouteGuideManager.onStop();
// if (BNDemoUtils.getBoolean(this, "float_window")) {
// mRouteGuideManager.onBackground();
// }}@Overrideprotected void onDestroy() {super.onDestroy();mRouteGuideManager.onDestroy(false);unInitTTSListener();mRouteGuideManager = null;}@Overridepublic void onBackPressed() {mRouteGuideManager.onBackPressed(false, true);}public void onConfigurationChanged(android.content.res.Configuration newConfig) {super.onConfigurationChanged(newConfig);mRouteGuideManager.onConfigurationChanged(newConfig);}@Overridepublic void setRequestedOrientation(int requestedOrientation) {}@Overridepublic boolean onKeyDown(int keyCode, android.view.KeyEvent event) {if (!mRouteGuideManager.onKeyDown(keyCode, event)) {return super.onKeyDown(keyCode, event);}return true;}private boolean supportFullScreen() {if (Build.VERSION.SDK_INT >= 21) {Window window = getWindow();int color;if (Build.VERSION.SDK_INT >= 23) {color = Color.TRANSPARENT;} else {color = 0x2d000000;}window.setStatusBarColor(color);if (Build.VERSION.SDK_INT >= 23) {window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);int uiVisibility = window.getDecorView().getSystemUiVisibility();if (mMode == IBNaviListener.DayNightMode.DAY) {uiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;}window.getDecorView().setSystemUiVisibility(uiVisibility);} else {window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);}window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);return true;}return false;}@Overridepublic void onRequestPermissionsResult(int requestCode, String[] permissions,int[] grantResults) {mRouteGuideManager.onRequestPermissionsResult(requestCode, permissions, grantResults);}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);mRouteGuideManager.onActivityResult(requestCode, resultCode, data);}
}
GuidePop.java
package com.dyys.baidumap.plugin.flutter_baidumap_plugin.activity;import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;import com.baidu.navisdk.adapter.struct.BNaviInfo;
import com.dyys.baidumap.plugin.flutter_baidumap_plugin.R;// 点击诱导面板 用于展示导航信息回调的pop
public class GuidePop extends PopupWindow {View mPopView;public GuidePop(Context context) {super(context);init(context);setpopwindow(context);}public void setdata(final BNaviInfo info) {mPopView.post(new Runnable() {@Overridepublic void run() {nextloadNameTv.setText("下个路口:" + info.getRoadName());nextloadDistanceTv.setText(info.getDistance() + "米 " + info.getTime() + "s后 ");turnIcon.setImageBitmap(info.getTurnIcon());}});}public void setdata(final String name) {mPopView.post(new Runnable() {@Overridepublic void run() {roadname.setText("当前:" + name);}});}public void setdata(final int remainDistance, final int remainTime) {mPopView.post(new Runnable() {@Overridepublic void run() {remainDistanceTv.setText("剩余 距离:" + remainDistance + "米 时间:" + remainTime + "s");}});}private void setpopwindow(final Context context) {this.setContentView(mPopView); // 设置Viewthis.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); // 设置弹出窗口的宽this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); // 设置弹出窗口的高this.setFocusable(true); // 设置弹出窗口可this.setBackgroundDrawable(new ColorDrawable(0x00000000)); // 设置背景透明this.setOutsideTouchable(true);this.setOnDismissListener(new OnDismissListener() { // 退出popupwidon时显示父控件原来的颜色@Overridepublic void onDismiss() {WindowManager.LayoutParams lp = ( (Activity) context).getWindow().getAttributes();lp.alpha = 1.0f;( (Activity) context).getWindow().setAttributes(lp);}});}TextView nextloadDistanceTv;TextView nextloadTimeTv;TextView nextloadNameTv;TextView remainDistanceTv;TextView remainTimeTv;TextView roadname;ImageView turnIcon;private void init(Context context) {LayoutInflater inflater = LayoutInflater.from(context);mPopView = inflater.inflate(R.layout.guidepopview, null);nextloadDistanceTv = mPopView.findViewById(R.id.nextload_distance);nextloadTimeTv = mPopView.findViewById(R.id.nextload_time);nextloadNameTv = mPopView.findViewById(R.id.nextload_name);remainDistanceTv = mPopView.findViewById(R.id.remainDistance);remainTimeTv = mPopView.findViewById(R.id.remainTime);turnIcon = mPopView.findViewById(R.id.turnIcon);roadname = mPopView.findViewById(R.id.roadname);}}
控制界面调用(只复制了方法)
//获取系统SD卡根目录路径String mSDCardPath = "";//应用在SD卡中的目录名(随便写)String APP_FOLDER_NAME = "flutter_baidumap_plugin";//起点纬度double startLat = 30.585814558410107;//起点经度double startLng = 104.055721746788;double endLat = 39.90882;double endLng = 116.39750;//起点名称String startName = "";//终点名称String endName = "";
/*** 开启导航** @param methodCall* @param result*/private void openNavigate(){mSDCardPath = getSdcardDir();//初始化initNavigate(mSDCardPath,APP_FOLDER_NAME);}private void initNavigate(String mSDCardPath,String APP_FOLDER_NAME){//初始化BaiduNaviManagerFactory.getBaiduNaviManager().init(context,mSDCardPath, APP_FOLDER_NAME, new IBaiduNaviManager.INaviInitListener() {String authinfo;@Overridepublic void onAuthResult(int status, String msg) {if (0 == status) {authinfo = "key校验成功!";} else {authinfo = "key校验失败, " + msg;}activity.runOnUiThread(new Runnable() {@Overridepublic void run() {Toast.makeText(context, authinfo, Toast.LENGTH_LONG).show();}});}@Overridepublic void initStart() {Toast.makeText(context, "百度导航引擎初始化开始", Toast.LENGTH_SHORT).show();}@Overridepublic void initSuccess() {Toast.makeText(context, "百度导航引擎初始化成功", Toast.LENGTH_SHORT).show();beginNavigate();// 初始化ttsinitTTS();}@Overridepublic void initFailed(int errCode) {Toast.makeText(context, "百度导航引擎初始化失败", Toast.LENGTH_SHORT).show();}});}private void beginNavigate(){//路线规划并通知发起专业导航BNRoutePlanNode sNode = new BNRoutePlanNode.Builder().latitude(startLat).longitude(startLng).name(startName).description(startName).build();BNRoutePlanNode eNode = new BNRoutePlanNode.Builder().latitude(endLat).longitude(endLng).name(endName).description(endName).build();List<BNRoutePlanNode> list = new ArrayList<>();list.add(sNode);list.add(eNode);BaiduNaviManagerFactory.getRoutePlanManager().routePlanToNavi(list,IBNRoutePlanManager.RoutePlanPreference.ROUTE_PLAN_PREFERENCE_DEFAULT,null,new Handler(Looper.getMainLooper()) {@Overridepublic void handleMessage(Message msg) {switch (msg.what) {case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_START:Toast.makeText(context.getApplicationContext(),"算路开始", Toast.LENGTH_SHORT).show();break;case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_SUCCESS:Toast.makeText(context.getApplicationContext(),"算路成功", Toast.LENGTH_SHORT).show();break;case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_FAILED:Toast.makeText(context.getApplicationContext(),"算路失败", Toast.LENGTH_SHORT).show();break;case IBNRoutePlanManager.MSG_NAVI_ROUTE_PLAN_TO_NAVI:Toast.makeText(context.getApplicationContext(),"算路成功准备进入导航", Toast.LENGTH_SHORT).show();Intent intent = new Intent(activity,DemoGuideActivity.class);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);activity.startActivity(intent);break;default:// nothingbreak;}}});}private void initTTS() {// 使用内置TTSBNTTsInitConfig config = new BNTTsInitConfig.Builder().context(getApplicationContext()).sdcardRootPath(mSDCardPath).appFolderName(APP_FOLDER_NAME).appId("2391...略").appKey("GNGGY8cqqaeMfxt0...略").secretKey("ChpYiwd3H...略").build();BaiduNaviManagerFactory.getTTSManager().initTTS(config);}
创建(复制)xml界面
guidepopview.xml(activity_main.xml是地图用到的)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:background="#000000"android:orientation="vertical"android:gravity="center_horizontal"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/roadname"android:textSize="24dp"android:textColor="#ffffff"android:layout_width="wrap_content"android:layout_height="wrap_content"/><ImageViewandroid:id="@+id/turnIcon"android:layout_width="wrap_content"android:layout_height="50dp"/><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><TextViewandroid:id="@+id/nextload_distance"android:textSize="24dp"android:textColor="#ffffff"android:layout_width="wrap_content"android:layout_height="wrap_content"/><TextViewandroid:id="@+id/nextload_time"android:textSize="24dp"android:textColor="#ffffff"android:layout_width="wrap_content"android:layout_height="wrap_content"/></LinearLayout><TextViewandroid:id="@+id/nextload_name"android:textColor="#ffffff"android:textSize="20dp"android:layout_width="wrap_content"android:layout_height="wrap_content"/><LinearLayoutandroid:orientation="horizontal"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextViewandroid:textColor="#ffffff"android:textSize="20dp"android:id="@+id/remainDistance"android:layout_width="wrap_content"android:layout_height="wrap_content"/><TextViewandroid:textColor="#ffffff"android:textSize="20dp"android:id="@+id/remainTime"android:layout_width="wrap_content"android:layout_height="wrap_content"/></LinearLayout></LinearLayout>
配置android界面
直截取了application
<application><!-- 一定要有这个 uses-library 不然点退出导航app闪退--><uses-library android:name="org.apache.http.legacy" android:required="false" /><serviceandroid:name="com.baidu.location.f"android:enabled="true"android:process=":remote"></service><serviceandroid:name="com.baidu.trace.LBSTraceService"android:enabled="true"android:process=":remote"></service><activityandroid:name=".page.BaseMap"android:configChanges="orientation|keyboardHidden|screenSize"android:label="@string/demo_title_createmaplist"android:screenOrientation="portrait" /><!-- 配这两个就行了 --><activityandroid:name=".activity.DemoGuideActivity"android:configChanges="orientation|keyboardHidden|screenSize"android:screenOrientation="portrait"android:theme="@android:style/Theme.NoTitleBar.Fullscreen" /><activityandroid:name=".activity.GuidePop"android:configChanges="orientation|keyboardHidden|screenSize"android:screenOrientation="portrait" /></application>
获取TTS服务 appid等
打开网址
https://ai.baidu.com/
进入控制台
点击语音技术
创建应用
应用名称、应用描述随便填,包名填上面gradle中的 applicationId
创建完毕后如下,复制后填入即可
效果
使用模拟机会闪退,因为没有模拟机对应的资源(我的模拟机是X86的)😭
总结
懵逼的时候先看demo