美文网首页
Android集成高德定位SDK,报ErrCode:7错误解决

Android集成高德定位SDK,报ErrCode:7错误解决

作者: S晔枫 | 来源:发表于2017-03-09 17:57 被阅读477次

    由于开发需要将项目从eclipse迁移到androidStudio上,结果运行就报错 ErrCode:7 errInfo:KEY错误;

    查找官方文档,说SHA1错误

    (接手的别人的项目)没办法啊,那就只有重新申请key了,重新获取SHA1,各种折腾,还是说key错误

    最后在网上找到这个方法  (加在定位前)

    //获取SHA1的方法===================================================================

                public staticString sHA1(Context context) {

                    try{

                            PackageInfo info = context.getPackageManager().getPackageInfo(

                            context.getPackageName(), PackageManager.GET_SIGNATURES);

                            byte[] cert = info.signatures[0].toByteArray();

                            MessageDigest md = MessageDigest.getInstance("SHA1");

                            byte[] publicKey = md.digest(cert);

                            StringBuffer hexString =newStringBuffer();

                            for(inti =0; i < publicKey.length; i++) {

                            String appendString = Integer.toHexString(0xFF& publicKey[i])

    .                        toUpperCase(Locale.US);

                            if(appendString.length() ==1)

                            hexString.append("0");

                            hexString.append(appendString);

                        }

                       returnhexString.toString();

                     }catch(PackageManager.NameNotFoundException e) {

                            e.printStackTrace();

                     }catch(NoSuchAlgorithmException e) {

                            e.printStackTrace();

                     }catch(Exception e) {

                            e.printStackTrace();

                     }

                return null;

              }

    //获取SHA1的方法===================================================================

    在代码中获取SHA1,注意 获取到的SHA1没有  “”,需自己添加上去,然后将它拷贝到  调试版安全码SHA1 中,这次终于好了,可以正常定位了。

    大家可以试试,亲测有效!

    相关文章

      网友评论

          本文标题:Android集成高德定位SDK,报ErrCode:7错误解决

          本文链接:https://www.haomeiwen.com/subject/xgcggttx.html