Android 应用程序需要 root 权限
我正在编写一个应用程序来访问许多系统设备节点。为了打开设备节点,我编写了本机方法,当我尝试执行它时,我无法打开设备节点,因为我的应用程序没有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先也是最重要的是,您显然需要一部已root的手机才能使所有这些工作正常进行。
话虽这么说,Android 不允许用户应用程序获得超级用户权限,即使是在已 root 的手机上也是如此。相反,它允许您使用超级用户权限启动新进程。
以超级用户身份运行的最简单方法是创建一个虚拟终端,如下所示:
使用输入和输出流,您现在可以有效地以 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:
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.