본문 바로가기

Linux/Android

안드로이드 루트 권한 요청하기 소스 코드

출처 : http://forum.xda-developers.com/showpost.php?p=2954887&postcount=7

They can use the Intent that is exposed by Superuser, that Shell uses to get root:

Code:
final int SUPERUSER_REQUEST = 2323; // arbitrary number of your choosing
Intent intent = new Intent("android.intent.action.superuser"); // superuser request
intent.putExtra("name", "Shell"); // tell Superuser the name of the requesting app
intent.putExtra("packagename", "koushikdutta.shell"); // tel Superuser the name of the requesting package
startActivityForResult(intent, SUPERUSER_REQUEST); // make the request!

Then, if the user presses Yes or Always, that Java application can call su just like normal:

Code:
Runtime.getRuntime().exec("su -c <your privileged command here>");

Otherwise, that command will fail.