打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Android C 语言读取系统属性
 

Android C 语言读取系统属性

 

    用 Qt Creator 写一个 Android 程序,需要读取 DNS 。C 语言怎么读呢,研究了一下,原来在 Android 的 C 库里,就有读取系统属性的方法。用 objdump 看了一下 libc.so ,找到了其中的函数。如下:

  1. 000095f0 g     F .text  00000014 __system_properties_init  
  2. 00009604 g     F .text  00000014 __system_property_find  
  3. 00009618 g     F .text  00000014 __system_property_find_nth  
  4. 0000962c g     F .text  00000014 __system_property_get  
  5. 00009640 g     F .text  00000014 __system_property_read  
  6. 00009654 g     F .text  00000014 __system_property_wait  

    头文件是 system_properties.h ,在 usr/include/sys目录下面。

    __system_property_get 可以用来获取一个属性值,函数原型如下:

  1. /* Look up a system property by name, copying its value and a 
  2. ** \0 terminator to the provided pointer.  The total bytes 
  3. ** copied will be no greater than PROP_VALUE_MAX.  Returns 
  4. ** the string length of the value.  A property that is not 
  5. ** defined is identical to a property with a length 0 value. 
  6. */  
  7. int __system_property_get(const char *name, char *value);  

    读取 DNS 的代码如下:

  1. char buf[PROP_VALUE_MAX];  
  2. __system_property_get("net.dns1", buf);  
  3. __system_property_get("net.dns2", buf);  

    读取其他属性类似,设置的话可以查看 system_properties.h 看函数用法。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
【c语言】使用gumbo解析HTML
Java中的String为什么是不可变的?
android如何获取系统开机时间
Android Property System
C# char 和string之间转换
VC中对剪切板的操作
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服