[Java for Android App Development] DannyGM16:
Thank's!

But I have another problem, I'm developing an app to copy files from assets to system. The code works, but the copy from /data/data/.. to /system/... take a long time and I don't know how to put a progress dialog. But this problem is strange, becouse the copy of the file is abot a minute after I close the app. I want to make a progress dialog in this time. Can you help me?? (I'm spanish, sorry for my english errors)

Notes:

1- Please, don't modify the function names, "reparar" corresponds a button

2- I know that I have a very dirty code, but only help in my problem, don't clean it

3- I wait for you to help me :D

public class MainActivity extends Activity {

ProgressDialog progress;
private static final String TAG = "Copy Example";

[MENTION=439709]override[/MENTION]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (RootTools.isRootAvailable()) {

} else {
finish();
}

}

public void reparar(View view) throws IOException, TimeoutException, RootDeniedException {
progress = ProgressDialog.show(this, "dialog title",
"dialog message", true);
copyfile1();
copyfile2();
copyfile1tosystem();
copyfile2tosystem();
End();
}
public void copyfile1() {
String data_storage_root = getApplicationContext().getFilesDir().toString();
InputStream is= null;
OutputStream os = null;

File h = new File(data_storage_root+"/file.format");

if (h.exists()) h.delete();
try {
is = getApplicationContext().getResources().getAssets().open("keypad/file.format");
os = new FileOutputStream(data_storage_root+"/file.format");
if (copy(is, os))
is.close();
os.flush();
os.close();
os = null;
Log.d(TAG, "success");
} catch (IOException e) {
Log.w(TAG, "failed copying certificate generic");
}
return;

}
public void copyfile2() {
String data_storage_root = getApplicationContext().getFilesDir().toString();
InputStream is= null;
OutputStream os = null;

File h = new File(data_storage_root+"/file2.format");

if (h.exists()) h.delete();
try {
is = getApplicationContext().getResources().getAssets().open("keypad/file2.format");
os = new FileOutputStream(data_storage_root+"/file2.format");
if (copy(is, os))
is.close();
os.flush();
os.close();
os = null;
} catch (IOException e) {
finish();
}
return;

}

public void copyfile1tosystem() throws IOException, TimeoutException, RootDeniedException {

CommandCapture command = new CommandCapture(0, "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system", "cp /data/data/com.fixer.gminipop/files/sec_key.kl /system/usr/keylayout/file.format", "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system");
RootTools.getShell(true).add(command);

}
public void copyfile2tosystem() throws IOException, TimeoutException, RootDeniedException {

CommandCapture command = new CommandCapture(0, "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system", "cp /data/data/com.fixer.gminipop/files/sec_keypad.kl /system/usr/keylayout/file2.format", "mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system");
RootTools.getShell(true).add(command);
}

public void End() {
progress.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Es necesario reiniciar")
.setTitle("Instalacion satisfactoria!")
.setCancelable(false)
.setNegativeButton("Hacerlo mas tarde",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setPositiveButton("Reiniciar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// metodo que se debe implementar

try {
ProcessBuilder pb = new ProcessBuilder(new String[] { "su", "-c", "/system/bin/reboot" });
java.lang.Process process = pb.start();
process.waitFor();
} catch (IOException e) {
}
// TODO Auto-generated method stub
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
});
AlertDialog alert = builder.create();
alert.show();
}

private boolean copy(InputStream in, OutputStream out){
try {
byte[] buffer = new byte[1024];
int read;
while (( read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
return true;
} catch (IOException e) {
Log.w(TAG, "fallo al copiar");
finish();
return false;
}
}
}