首页 / 浏览问题 / 移动GIS / 问题详情
SuperMap imobile示例数据运行后白屏
3EXP 2023年03月15日

使用产品:iMobile 11i 操作系统:win10 x64

手机Android版本:10 

问题详细描述:根据帮助文档写完代码,并将许可文件和地图数据放置在手机相应位置后,可以成功运行并且不报错,但是会闪退。

  super.onCreate(savedInstanceState);
        requestPermissions();
        setContentView(R.layout.activity_main);
        MapControl mapControl = null;
        String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();

        //设置许可文件路径(默认路径“/SuperMap/license/”)
        Environment.setLicensePath(rootPath + "/SuperMap/license/");

        //组件功能必须在Environment初始化之后才能调用
        Environment.initialization(this);
        setContentView(R.layout.activity_main);

        //打开工作空间
        Workspace m_workspace = new Workspace();
        WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();
        info.setServer(rootPath + "/SuperMap/GeometryInfo/World.smwu");
        info.setType(WorkspaceType.SMWU);
        m_workspace.open(info);

        //将地图显示控件和工作空间关联
        MapView m_mapView = findViewById(R.id.Map_view);
        mapControl = m_mapView.getMapControl();
        mapControl.getMap().setWorkspace(m_workspace);

        //打开工作空间中的第二幅地图
        String mapName = m_workspace.getMaps().get(1);
        mapControl.getMap().open(mapName);
        mapControl.getMap().refresh();

根据网上搜索来的解决办法,添加了获取权限的弹窗,运行时不闪退了但是会一直白屏且无法退出,关闭手机再重新打开后白屏消失,但是始终无法真正启动应用。

  private void requestPermissions() { //Android6.0以上设备设置动态权限
        // 检查是否拥有权限
        String[] permissions = {
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.READ_PHONE_STATE,
                Manifest.permission.ACCESS_WIFI_STATE,
                Manifest.permission.ACCESS_NETWORK_STATE,
                Manifest.permission.CHANGE_WIFI_STATE,
        };

        String permission = null;
        int id = 0;
        boolean isBreak = false;
        int checkCallPhonePermission = 0;
        for (int i = 0; i < permissions.length; i++) {
            permission = permissions[i];
            checkCallPhonePermission = checkSelfPermission(permission);
            if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(permissions, id);
                isBreak = true;
                break;
            }
        }
    }

...