2015-10-05 41 views
0

我怎么能拉从DDMS数据库文件,当设备连接?我知道如何,而在Android模拟器运行拉。但我想将其设备连接时?请帮忙解决这个问题。怎么拉从DDMS数据库连接设备时

+0

的可能的复制[如何查看在设备的Android SQLite数据库(http://stackoverflow.com/questions/19194576/how-to -view最sqlite的数据库,在设备,机器人) – Skynet

+0

你需要将设备的root访问权限去做。你的设备是否植根? –

回答

0

我想我明白你的问题,你问的路径从Android设备抓取数据库。

我们无法获取一些设备数据库,所以我认为可能的解决方案是在您的项目中创建一个备份按钮,从应用程序的私人文件夹复制数据库并将其粘贴到SD卡。那么你可以通过使用SQLite浏览器来访问数据库。

这里是复制代码数据库:

// method to get backup 
    public void BackupDatabase() throws IOException 
    { 
     try { 
       File sd = new File(Environment.getExternalStorageDirectory()+"");//getBaseContext().getFilesDir(); 
       File data = Environment.getDataDirectory(); 

       if(sd == null || !sd.canWrite()){ 
        sd = getBaseContext().getFilesDir(); 
       } 
      if (sd.canWrite()) 
      { 
       String currentDBPath = "/data/your.package.name/databases/YourDatabaseName"; 
       File temp = new File(sd, "BackupFolderInSDCard"); 
       if(!temp.exists()) 
        temp.mkdirs(); 

       File backupDB = new File(temp,"backup.db"); 
       File currentDB = new File(data, currentDBPath); 

       if (currentDB.exists()) 
       { 
        FileInputStream fis = new FileInputStream(currentDB); 
        BufferedInputStream bis = new BufferedInputStream(fis,1024); 

        FileOutputStream fos = new FileOutputStream(backupDB); 
        BufferedOutputStream bos = new BufferedOutputStream(fos, 1024); 

        byte arr[] = new byte[1024]; 
        int ch; 
        while((ch = bis.read(arr)) != -1) 
        { 
         bos.write(arr, 0, ch); 
        } 

        bos.close(); fos.close(); 
        bis.close(); fis.close(); 
//     Toast.makeText(getBaseContext(), "File Saved To\n"+ backupDB.getAbsolutePath(), Toast.LENGTH_LONG).show(); 
        Toast.makeText(getBaseContext(), "Database Stored in SD Card", Toast.LENGTH_LONG).show(); 
       } 
       else 
       { 
        Toast.makeText(getBaseContext(), "Database Doesn't Exist"+ backupDB.getAbsolutePath(), Toast.LENGTH_LONG).show(); 
       }