Skip to content

Instantly share code, notes, and snippets.

@angad
Created August 19, 2011 18:42
Show Gist options
  • Save angad/1157639 to your computer and use it in GitHub Desktop.
Save angad/1157639 to your computer and use it in GitHub Desktop.
CopyNative
/**
* Copies the native binary from resource to path
*
* @param path
* path to where the native binary needs to be copied
*
* @param resource
* integer value of the resource (e.g. R.raw.synscanner)
*
*/
protected void CopyNative(String path, int resource) {
InputStream setdbStream = getResources().openRawResource(resource);
try {
byte[] bytes = new byte[setdbStream.available()];
DataInputStream dis = new DataInputStream(setdbStream);
dis.readFully(bytes);
FileOutputStream setdbOutStream = new FileOutputStream(path);
setdbOutStream.write(bytes);
setdbOutStream.close();
//Set executable permissions
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("chmod 755 " + path + "\n");
os.writeBytes("exit\n");
os.flush();
}
catch (Exception e) {
nsandroid.resultPublish("Unable to Copy native binary " + e.getMessage());
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment