TShopping

 找回密碼
 註冊
搜索
TShopping 精選文章 Android 手機開發 查看內容

Android: Writing file on system partition and use chmod or chown

2013-10-19 00:16| 發佈者: woff| 查看: 1842| 評論: 0|原作者: woff

摘要: FileOutputStream out = openFileOutput(myfile.test, MODE_WORLD_READABLE); File f = getFileStreamPath(myfile.test); writeDataToOutputStream(out); out.close(); String filename = f.getAbsolutePath(); Runt ...
 
  1. FileOutputStream out = openFileOutput("myfile.test", MODE_WORLD_READABLE);
  2. File f = getFileStreamPath("myfile.test");
  3. writeDataToOutputStream(out);
  4. out.close();
  5. String filename = f.getAbsolutePath();
  6. Runtime r = Runtime.getRuntime();
  7. Process suProcess = r.exec("su");
  8. DataOutputStream dos = new DataOutputStream(suProcess.getOutputStream());
  9. dos.writeBytes("chown 0.0 " + filename + "\n");
  10. dos.flush();
  11. dos.writeBytes("chmod 644 " + filename + "\n");
  12. dos.flush();
  13. dos.writeBytes("mv " + filename + " /system/myfile.test\n");
  14. dos.flush();
復制代碼

The only thing left (not include din the code above) is to make /system writable. May be one additional command like mount -o rw,remount /system is sufficient - will test that.

在改變檔案權限時,請先r.exec("su");
就能正常執行下面語句

最新評論



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-5-6 13:24 , Processed in 0.040394 second(s), 20 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

返回頂部