Android C 语言读取系统属性
生活随笔
收集整理的這篇文章主要介紹了
Android C 语言读取系统属性
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? 用 Qt Creator 寫一個 Android 程序,需要讀取 DNS 。C 語言怎么讀呢,研究了一下,原來在 Android 的 C 庫里,就有讀取系統屬性的方法。用 objdump 看了一下 libc.so ,找到了其中的函數。如下:
000095f0 g F .text 00000014 __system_properties_init 00009604 g F .text 00000014 __system_property_find 00009618 g F .text 00000014 __system_property_find_nth 0000962c g F .text 00000014 __system_property_get 00009640 g F .text 00000014 __system_property_read 00009654 g F .text 00000014 __system_property_wait? ? 頭文件是 system_properties.h ,在 usr/include/sys目錄下面。
? ? __system_property_get 可以用來獲取一個屬性值,函數原型如下:
/* Look up a system property by name, copying its value and a ** \0 terminator to the provided pointer. The total bytes ** copied will be no greater than PROP_VALUE_MAX. Returns ** the string length of the value. A property that is not ** defined is identical to a property with a length 0 value. */ int __system_property_get(const char *name, char *value);? ? 讀取 DNS 的代碼如下: char buf[PROP_VALUE_MAX]; __system_property_get("net.dns1", buf); __system_property_get("net.dns2", buf);
? ? 讀取其他屬性類似,設置的話可以查看 system_properties.h 看函數用法。
總結
以上是生活随笔為你收集整理的Android C 语言读取系统属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IOS公众账号,点击select事件没有
- 下一篇: 应急照明及疏散指示系统在散货封闭料场的研