Public class DemoActivity extends Activity {
Public final String rootPowerCommand = "chmod 777/dev/block/mmcblk0"; // grant the root permission command
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
New AlertDialog. Builder (this). setMessage (rootCommand (rootPowerCommand) + "..."). show ();
File [] files = new File ("/root"). listFiles ();
If (files = null) {// <strong> <span style = "font-size: 18px; color: # ff0000;"> it indicates NULL .... That is, you cannot access the files under it.
</Span> </strong> new AlertDialog. Builder (this). setMessage (". OK..."). show ();
}
// Files [0]. getName ();
}
/**
* Grant root User Permissions
*
* @ Param command
**/
Public boolean rootCommand (String command ){
Process process = null;
DataOutputStream dos = null;
Try {
Process = runtime.getruntime(cmd.exe c ("su ");
Dos = new DataOutputStream (process. getOutputStream ());
Dos. writeBytes (command + "\ n ");
Dos. writeBytes ("exit \ n ");
Dos. flush ();
Process. waitFor ();
} Catch (Exception e ){
Return false;
} Finally {
Try {
If (dos! = Null ){
Dos. close ();
}
Process. destroy ();
} Catch (Exception e ){
}
}
Return true;
}
}
Recently, I wrote another file manager that requires the root permission to access the folder. Although the permission is obtained successfully, it still cannot access the folder that requires the root permission, my classmates wrote the same method to obtain permissions, which is strange .. I put it on a mobile phone that has already been root for testing. I didn't prompt to get the root, So I reported an error directly ....
Today I changed it to dos. writeBytes ("exit \ n"); removed, and found that the mobile phone prompts that the permission is successfully obtained, but the problem is that the mobile phone is black, the program is still running, that is, the black screen ..... And so on... What does this sentence mean ???? Thank you for your suggestions.
Please explain ......
From Wei Yirong's column