使用产品:imobile 11i 操作系统:win10 x64
手机Android版本:10 手机操作系统:小米10pro
按照示例写完代码后,可以成功运行,也不报错,但是app打开即闪退。
根据网上搜索来的解决方案后编写代码实现app运行弹窗选择权限后,不闪退但打开后会持续白屏且无法退出,直接将手机息屏再重新开启后自动退出。 具体代码如下
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;
}
}
}
许可文件和地图数据文件均按照代码中的位置放在手机中
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);