Created
August 19, 2011 18:42
-
-
Save angad/1157639 to your computer and use it in GitHub Desktop.
CopyNative
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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