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

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

2013-10-19 00:16| 發佈者: woff| 查看: 1950| 評論: 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, 2025-4-30 18:29 , Processed in 0.015682 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

返回頂部