BDMapSDKException: context must be an ApplicationContext 解决方案

如果参考百度地图开发文档使用

SDKInitializer.initialize(this);

会报错如下错误

BDMapSDKException: context must be an ApplicationContext 解决方案_第1张图片

 解决方案 

        SDKInitializer.initialize(this.getApplicationContext());

然后会发现还是会报错

BaiduMapSDKException: not agree privacyMode, please invoke SDKInitializer.setAgreePrivacy(Context, boolean) function

根据提示 我们设置AgreePrivacy 注意代码的先后顺序!

  SDKInitializer.setAgreePrivacy(this.getApplicationContext(),true);
        LocationClient.setAgreePrivacy(true);
        SDKInitializer.initialize(this.getApplicationContext());
        setContentView(R.layout.activity_main);

你可能感兴趣的:(笔记,android,studio,android,java)