打开以前下载的数据库

时间:2020-05-17 12:49:18

标签: java android firebase android-sqlite firebase-storage

因此,该程序从Firebase存储中下载文件, 我的下载代码是:

private void downloadFiles(Context context, String fileName, String destinationDirectory, String url) {
    DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    Uri uri = Uri.parse(url);
    DownloadManager.Request request = new DownloadManager.Request(uri);

    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    request.setDestinationInExternalFilesDir(context, destinationDirectory, fileName);

    downloadManager.enqueue(request);
}

public void downloading(final String name) {
    downloadRef = storage.getInstance().getReference().child(name);
    downloadRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
        @Override
        public void onSuccess(Uri uri) {
            String url = uri.toString();
            downloadFiles(Main2Activity.this, name,  Environment.getExternalStorageState((File) Downloads), url);
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Toast.makeText(Main2Activity.this, "Failed!!!", Toast.LENGTH_LONG).show();
        }
    });
}

然后我要使用此数据库,所以我尝试使用以下方法打开它:

database = SQLiteDatabase.openDatabase(Environment.getExternalStorageState((File) Downloads) + "/" + name, null, SQLiteDatabase.OPEN_READWRITE);

但它说

由以下原因引起:android.database.sqlite.SQLiteCantOpenDatabaseException:未知错误(代码14):无法打开数据库

我该如何解决?

0 个答案:

没有答案