Frage

I am writing an application to access the many of the system device nodes. To open the device nodes, I wrote native methods, When I am trying to execute it, I am unable to open the device node as there is no root permissions to my application. Could any one please tell give root permission to my android application. device details: android 2.0.1 - motorola milestone.

rtc_fd=open("/dev/rtc",0777);
if(rtc_fd == -1) {
    __android_log_write(ANDROID_LOG_ERROR, "","UNABLE TO OPEN THE DEVICE....");
    strcpy(result_string,"Fail: /dev/rtc open error\n");
    __android_log_write(ANDROID_LOG_ERROR, ""," DEVICE...ERROR. ");
    return result_string;
}

ret = ioctl(rtc_fd, RTC_RD_TIME, &rtc_tm);
if (ret == -1) {
    strcpy(result_string,"Fail: rtc ioctl RTC_RD_TIME error\r\n");
    return result_string;
}

It is always saying UNABLE TO OPEN DEVICE, could any one please suggest a solution to open a device node.

War es hilfreich?

Lösung

First and foremost, you will obviously need a rooted phone for any of this to work.

That being said, Android does not allow for a user-application to gain super-user rights, even on a rooted phone. Instead, it allows you to launch a new process with super-user rights.

The easiest method for running things as super-user is to create a virtual terminal, as follows:

Process proc = Runtime.getRuntime().exec("su");
DataOutputStream standard_in = new DataOutputStream(proc.getOutputStream());
DataInputStream standard_out = new DataInputStream(proc.getInputStream());

Using the input and output streams you now effectively have console access as root, which you can use to run typical command-line commands, or to run the process that accesses your device for you.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top