Android中如何绑定小于1024的端口?
我有一个 Android 服务尝试绑定到服务器套接字端口 24。由于它是特权端口,因此它失败并出现绑定异常。 我想知道我需要做什么才能使其正常工作。 我发现这个问题在这个论坛上被问过几次,但没有解决。
该服务在运行 Android 的设备上运行。我们为该设备构建Android平台。我们拥有所需的一切控制权。
I have an Android service trying to bind to a server socket port 24. As it is privileged port, it is failing with a bind exception.
I am wondering what I need to do to get this working.
I see this was asked couple of times in this forum, but without a resolution.
This service runs on a device that runs on Android. We build android platform for the device. We have all the control we need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要绑定到小于 1024 的端口,您需要成为 root,有两种方法可以做到这一点。
系统应用:应用程序应安装到 /system/apps 文件夹中,并从该文件夹中以 root 身份运行。不过,对于一些签名问题,可以提供帮助 。分发也是系统应用程序的一个问题。
su 二进制文件:可以使用简单的
exec("su -c [command]")
调用 su 二进制文件。但事情说起来容易做起来难。你需要运行一个 android 进程而不仅仅是一个命令。因此,有 libsuperuser 为您提供方法并具有完整的 文档页面。To bind to a port less than 1024, you need to be root and there are two ways of doing that.
System app : The app should be installed into /system/apps folder from where it shall be run as root. However, there are some signature issues for which help is available. Distribution is also a problem with system apps.
su binary : The su binary can be invoked using a simple
exec("su -c [command]")
. But things are easier said than done. You need to run an android processes not just a single command. Hence, there is libsuperuser which provides you the methods and has a full-length doc page.这是一个非常相似的问题:以 root、android 身份运行安全 API 调用,尽管他们出于不同的原因尝试以 root 身份运行。
这让我想知道如何安装“系统应用程序”,我看到了这个: https://android.stackexchange.com/questions/27/rooted-how-to-install-a-system-app
This is a very similar question: Run secure API calls as root, android, though they are trying to run as root for a different reason.
That made me wonder about installing 'system apps', and I saw this: https://android.stackexchange.com/questions/27/rooted-how-to-install-a-system-app