注册

登陆时android.database.sqlite.SQLiteCantOpenDatabaseException错误

登陆时报错
 
        EMClient.getInstance().login(currentUsername,currentPassword,new EMCallBack() {//回调
@Override
public void onSuccess() {
EMClient.getInstance().groupManager().loadAllGroups();
EMClient.getInstance().chatManager().loadAllConversations();
Log.d("main", "登录聊天服务器成功!马上跳转MainActivity.class");

startActivityForResult(new Intent(LoginActivity.this, MainActivity.class), 0);
finish();
}

结果是Android6.0以后版本动态权限的问题 
已邀请:

陈日明 - 90后IT男

这个报错不影响项目的运行
找到问题了..是app中build.gradle的targetSdkVersion 问题  解决方法有两个
1: 改成23以下的版本.
2:如果是23以上的版本.LoginActivity.java添加两个常量
private static final int REQUEST_EXTERNAL_STORAGE = 1; private static String[] PERMISSIONS_STORAGE = { "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE" };
在onCreate()方法中.添加
try { //检测是否有写的权限 int permission = ActivityCompat.checkSelfPermission(this, "android.permission.WRITE_EXTERNAL_STORAGE"); if (permission != PackageManager.PERMISSION_GRANTED) { // 没有写的权限,去申请写的权限,会弹出对话框 ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE,REQUEST_EXTERNAL_STORAGE); } } catch (Exception e) { e.printStackTrace(); }
 

要回复问题请先登录注册