2015-10-05 66 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(); 
       }