找不到数据库路径是不可能的

时间:2013-07-17 06:22:20

标签: android

我对android开发很新,现在我正在尝试通过扩展SQLiteOpenHelper的类创建数据库。我确信数据存储在我的Nexus 7(我用来测试我的应用程序的设备)的某个地方,但是我找不到数据库的路径。

我一直在寻找其他类似问题,所有答案都指向在 data / data / com.example.projet_name / databases / database_name 找到数据库,但我没有这样的路径在我的设备上。

关于问题可能是什么的任何想法?或许我还应该寻找其他途径?

感谢您的时间。

已编辑:

请从我之前的帖子中找到我的代码here

现在,当我运行应用程序时出现以下错误。我希望它在某种程度上有所帮助。

07-17 08:28:20.130: E/libgps(486): LIBGPS: Cannot communicate (write) with a GPSD
07-17 08:28:20.130: E/libgps(486): IPC Communication Error, /tmp/11862727/customers/Asustek/Tabletandroid/../../../proprietary/deliverables/android/gps_interface/../gps_interface/gpsi_client/GpsiClient.cpp:1178 agps_ril_update_network_state

2 个答案:

答案 0 :(得分:0)

如何将dbname设置为完整路径:

String DATABASE_NAME = "/data/data/"+packageName+"db.db";

或将您的数据库放入SD卡:

String DATABASE_NAME= Environment.getExternalStorageDirectory()+packageName+"db.db";

在代码中传递dbPath:

public DatabaseImplementation(Context context) 
{
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

答案 1 :(得分:0)

如果您正试图从设备获取存储在应用程序包中的数据库,您将无法从设备/数据/数据/应用程序包名称/数据库/直接访问..您可以使用helperclass bt direct export nt访问和修改poss AFAIK ... bt from emulator u cn gt

enter image description here

如果要从应用程序包中导出sd卡中的数据库

试试这个

private void copyFromDataPackgeToSdCard() throws IOException {
    try {
        File sdCard = Environment.getExternalStorageDirectory();
        File appDataDir = Environment.getDataDirectory();
        if (sdCard.canWrite()) {
            String currentDBPath = "//data//" + getPackageName()
                    + "//databases//"
                    + DatabaseImplementation.DATABASE_NAME;
            String backupDBPath = DatabaseImplementation.DATABASE_NAME;
            File currentDatabase = new File(appDataDir, currentDBPath);
            File backupDatabase = new File(sdCard, backupDBPath);

            if (currentDatabase.exists()) {
                FileChannel src = new FileInputStream(currentDatabase)
                        .getChannel();
                FileChannel dst = new FileOutputStream(backupDatabase)
                        .getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                dst.close();
            }
        }
    } catch (Exception e) {
        Log.e("copyFromDataPackgeToSdCard", e.getMessage());
    }
}