2012-02-24 24 views
0

我有根源的手機。 我想以編程方式將數據/數據/ com.android.providers.telephony/databases/mmssms.db 文件複製到sd卡。如何以編程方式將sms數據庫從根源手機複製到SD卡

我收到錯誤,如 java.io.FileNotFoundException:/data/data/com.android.providers.telephony/databases/mmssms.db(拒絕)

請幫我... 。

請多關照......

我使用下面的代碼在SD卡複製數據庫 ' 嘗試{

  File sd = Environment.getExternalStorageDirectory(); 
      String path = Environment.getDataDirectory().getAbsolutePath(); 
      File data = Environment.getDataDirectory(); 
      String currentDBPath = "/data/com.android.providers.telephony/databases/mmssms.db"; 
      String backupDBPath = "/bkup/mmssms.db"; 
      File currentDB = new File(data, currentDBPath); 
      File backupDB = new File(sd, backupDBPath); 
      // Local database 
      InputStream input = new FileInputStream(currentDB); 

      // Path to the external backup 
      OutputStream output = new FileOutputStream(backupDB); 

      // transfer bytes from the Input File to the Output File 
      byte[] buffer = new byte[1024]; 
      int length; 
      while ((length = input.read(buffer))>0) { 
       output.write(buffer, 0, length); 
      } 

      output.flush(); 
      output.close(); 
      input.close(); 
    } catch (Exception e) { 
     // TODO: handle exception 
     Toast.makeText(this, e.getMessage().toString(), Toast.LENGTH_LONG).show(); 
    }` 

回答

0

您試圖從其他應用程序複製數據庫。這不被允許。即使您的手機已經植根,您的應用程序尚未獲得root權限。

String currentDBPath = "/data/com.android.providers.telephony/databases/mmssms.db"; 

您需要先授予root權限,並使用shell命令來拷貝文件,就像這樣(CP /data/..../xxx.db /sdcard/xxx.db)

Read command output inside su process

只是使用的方法在這篇文章中,改變shell命令...

stdin.writeBytes("cp /data/data/com.android.providers.telephony/databases/mmssms.db /sdcard/\n"); // \n executes the command 
+0

感謝您的快速反應洞。我在這部分是新手,所以我可以通過編程來完成這個任務嗎?我提到的路徑是我的手機中的短信數據庫的實際路徑。 – 2012-02-24 05:20:23

+0

我自己做了:D,方法如上。 – dong221 2012-02-24 06:00:56

+0

是的!!!!!!感謝哥們......你是gr8。我得到它的工作......感謝您的幫助.... – 2012-02-24 06:16:50

相關問題