To execute a command with root privileges on Android, you need to use the "su" command followed by the actual command you want to execute. In your case, you want to copy a file, so you should use the "cp" command instead of "mv". The "mv" command moves the file, while "cp" creates a copy.
Here's how you can modify your code to copy the file with root privileges:
try {
Process process = Runtime.getRuntime().exec(new String[]{"su", "-c", "cp /storage/emulated/0/super/hi.txt /storage/emulated/0/"});
process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
This code snippet first requests root access using "su" and then executes the "cp" command to copy the file. The "-c" flag is used to pass the command as a single argument to the shell.
Please note that this approach requires a rooted device, and your app must have the necessary permissions to access the file system. Additionally, using root access in your app can pose security risks, so make sure to handle it carefully and inform your users about the implications.
Update:
Kotlin implementation as provided by @ᘜᗩᑌᖇᗩᐯ:
Runtime.getRuntime().exec(arrayOf("su", "-c","cp /storage/emulated/0/super/hi.txt /storage/emulated/0/" ) )