1)AndroidManifest.xml
增加权限,声明service和ak鉴权
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:name="BaiduMobAd_STAT_ID"
android:value="48ae76de3f" />
android:value="bAZLoLtUxVPWs6fpnRBLOY8yFHjKu0jE" />
android:name="com.baidu.location.f"
android:enabled="true"
android:process=":remote" />
2)导入项目所需的jar包和so
把jar包放入lib目录下
BaiduNaviSDK_3.3.1.jar
galaxy_lite_lbs_v2.0.jar
httpmime-4.1.2.jar
lbsCoreSDK.jar
把armeabi目录下的所有so放到libs/armeabi下
在build.gradle android{}中加入
sourceSets {
main {
jniLibs.srcDir 'libs'
}
}
把assets目录下的所有资源文件放到app/src/main/assets目录下
3)初始化
在使用SDK前,应该先进行百度服务授权和引擎初始化
BaiduNaviManager.getInstance().init(this,
Environment.getExternalStorageDirectory().toString(),
"BNSDKSimpleDemo",
new BaiduNaviManager.NaviInitListener() {
@Override
public void onAuthResult(int status, String msg) {
if (0 == status) {
authinfo = "key校验成功!";
} else {
authinfo = "key校验失败, " + msg;
}
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, authinfo, Toast.LENGTH_LONG).show();
}
});
}
public void initSuccess() {
Toast.makeText(MainActivity.this, "百度导航引擎初始化成功", Toast.LENGTH_SHORT).show();
initSetting();
}
public void initStart() {
Toast.makeText(MainActivity.this, "百度导航引擎初始化开始", Toast.LENGTH_SHORT).show();
}
public void initFailed() {
Toast.makeText(MainActivity.this, "百度导航引擎初始化失败", Toast.LENGTH_SHORT).show();
}
}, null, ttsHandler, ttsPlayStateListener);
private void initSetting() {
BNaviSettingManager
.setShowTotalRoadConditionBar(BNaviSettingManager.PreViewRoadCondition.ROAD_CONDITION_BAR_SHOW_ON);
BNaviSettingManager.setVoiceMode(BNaviSettingManager.VoiceMode.Veteran);
// BNaviSettingManager.setPowerSaveMode(BNaviSettingManager.PowerSaveMode.DISABLE_MODE);
BNaviSettingManager.setRealRoadCondition(BNaviSettingManager.RealRoadCondition.NAVI_ITS_ON);
BNaviSettingManager.setIsAutoQuitWhenArrived(true);
Bundle bundle = new Bundle();
// 必须设置APPID,否则会静音
bundle.putString(BNCommonSettingParam.TTS_APP_ID, "10693742");
BNaviSettingManager.setNaviSdkParam(bundle);
}