java - java sqlite export import for Android10 以上
问题描述
下面的 java 代码在 Android 10 及更低版本中使用,由于限制,在 Android 10 及更高版本中不再可用。如何使以下代码适用于 android 10 以上版本。谢谢您的帮助。
public static boolean importDb(Context context) {
String str = "Notes";
File file = new
File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), str);
if (checkDbIsValid(file)) {
return false;
}
try {
@SuppressLint("WrongConstant") SQLiteDatabase openDatabase =
SQLiteDatabase.openDatabase(file.getPath(), null, 1);
Cursor query = openDatabase.query(true, DATABASE_TABLE, null, null, null, null, null, null, null);
NotesDbAdapter notesDbAdapter = new NotesDbAdapter(context);
notesDbAdapter.open();
query.moveToPosition(-1);
while (query.moveToNext()) {
notesDbAdapter.createNote(query.getString(1), query.getString(2), query.getString(3),
query.getString(4));
}
openDatabase.close();
query.close();
notesDbAdapter.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
解决方案
推荐阅读
- reactjs - 无法在另一个组件上显示搜索的输出
- apache-camel - 来自远程服务器的 XSLT 2.0 文件未在 ServiceMix 的蓝图骆驼路由中处理
- wordpress - 如何将托管在 wordpress 上的现有网站迁移到 GKE 上的 kubernetes?
- sql - 如何按类别添加自增字段
- android - 我的 React Native 应用程序卡在加载循环中
- javascript - 为什么不能重新分配函数表达式的名称?
- css - 将 css 关键帧转换为原生反应
- c++ - 即使我在着色器中使用了变量,glGetUniformLocation 也会返回 -1
- python - 删除具有“KA”子字符串的列表元素,但并非所有元素都被删除。为什么?
- java - 如何在 Android 中为文本添加 href 链接?