Unknown error (SQLite code 14): could not open database (How to Fix)

Today, before I ran a project, I suddenly crashed as soon as I ran it. It felt very strange.

Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (Sqlite code 14): Could not open database, (OS error - 13:Permission denied)

seems to lack permissions according to the log prompt, because the project is only using storage, then look at the permissions in the androidmanifest.xml and see

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

these two permissions are in ah, this is what is the matter, baidu is not added under the permission. Finally, it suddenly occurred to me that my phone was running on Android6.0. Then, to verify it, I found a 4.0 system and ran it directly. Once I found the problem, I would solve it. Many permissions have appeared since Android6.0, even though they are configured in androidmanifest.xml, and must be requested manually, or the permissions must be turned on in Settings – applications – permissions.
after 6.0 system with some permissions can be carried out such operation:

public static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
/**
* Verify access to the sd card
*
* @param activity
*/
public boolean verifyStoragePermissions(Activity activity) {
/*******below android 6.0*******/
if (Build.VERSION.SDK_INT < 23) {
return true;
}
int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
return false;
} else {
return true;
}

}

Override in the Activity that invokes the requested permission. 
/**
 * :: Callbacks to request permissions
 *
 * @param requestCode
 * @param permissions
 * @param grantResults
 */
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_EXTERNAL_STORAGE) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
showToast("Authorization Success");
} else {
showToast("Authorization failed, please set open permissions.");
}
}
}

You can change the permission name to request another permission. Keep a small journal and hopefully help someone in need.

Read More: