Android 应用程序需要 root 权限

发布于 2024-12-09 13:51:56 字数 662 浏览 4 评论 0原文

我正在编写一个应用程序来访问许多系统设备节点。为了打开设备节点,我编写了本机方法,当我尝试执行它时,我无法打开设备节点,因为我的应用程序没有 root 权限。任何人都可以告诉我给我的 Android 应用程序授予 root 权限吗?设备详细信息:android 2.0.1 - 摩托罗拉里程碑。

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;
}

总是说无法打开设备,有人可以建议一种打开设备节点的解决方案吗?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情废物 2024-12-16 13:51:56

首先也是最重要的是,您显然需要一部已root的手机才能使所有这些工作正常进行。

话虽这么说,Android 不允许用户应用程序获得超级用户权限,即使是在已 root 的手机上也是如此。相反,它允许您使用超级用户权限启动新进程。

以超级用户身份运行的最简单方法是创建一个虚拟终端,如下所示:

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

使用输入和输出流,您现在可以有效地以 root 身份访问控制台,您可以使用它来运行典型的命令行命令,或运行为您访问您的设备的过程。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文