I know this has been asked a lot but never answered. I definetly need to write files to root there is no other solution. I currently use this code but it doesn't show anything new in /system/. I want to copy file from my assets to the /system folder (with it's subdir's)
public void installFiles(View v) {
try {
Runtime.getRuntime().exec("su");
} catch (IOException e) {
mDebugView.append(e.toString());
}
copyPath("system/bin", "/system/bin/");
copyPath("system/lib", "/system/lib/");
copyPath("system/etc", "/system/etc/");
copyPath("system/etc/audio", "/system/etc/audio/");
copyPath("system/etc/soundimage", "/system/etc/soundimage/");
copyPath("system/lib/soundfx", "/system/bin/soundfx/");
}
public void copyPath(String from, String to) {
mDebugView.append("Copying path assets/" + from + " to " + to + "
");
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list(from);
for (String filename : files) {
mDebugView.append(filename + "...
");
if (new File(filename).isFile()) {
mDebugView.append("Copying " + filename + "
");
InputStream in = null;
OutputStream out = null;
in = assetManager.open(filename);
out = new FileOutputStream(to);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
}
}
} catch (IOException e) {
Log.e(this.getClass().toString(), e.toString());
mDebugView.append(e.toString() + "
");
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
mDebugView.append("..");
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…