Android系统开发小知识点

来源:互联网 发布:js实现发表评论功能 编辑:程序博客网 时间:2024/05/17 02:06

目的在于记录平时开发过程中遇到的一些知识点和小技巧!

1、添加和获取系统属性

(1)系统属性有两种:

ADDITIONAL_BUILD_PROPERTIES   写入/system/build.prop文件

ADDITIONAL_DEFAULT_PROPERTIES  写入default.prop文件

(2)添加方法

一般在build/core/main.mk中添加,以便在编译时所有的架构或者平台都能读取得到。

例子:添加一个名称为test,默认值为hello的属性

ADDITIONAL_BUILD_PROPERTIES +=ro.test=hello

或者

ADDITIONAL_DEFAULT_PROPERTIES +=ro.test=hello

ro表示read only的意思。

(3)获取系统属性

1)在系统终端用命令行获取

getprop | grep test 获取上面设置的test的属性值

2)在代码里面获取

jni(c++)层和java层的获取方式略有区别。

jni层:

char *tmp;

property_get("ro.test",tmp,NULL)

property_get不会返回属性值,只会把ro.test属性的值放到tmp中。

java层:

SystemProperties.get("ro.test"),它直接返回属性的值。


2、把指定的文件编译进来

在.mk文件中添加,例如

PRODUCT_COPY_FILES += \

       bionic/libc/zoneinfo/zoneinfo.version:system/usr/share/zoneinfo/zoneinfo.version \

       bionic/libc/zoneinfo/zoneinfo.dat:system/usr/share/zoneinfo/zoneinfo.dat \

       bionic/libc/zoneinfo/zoneinfo.idx:system/usr/share/zoneinfo/zoneinfo.idx

意思为把bionic/libc/zoneinfo/下面的3个文件在编译时放到system/usr/share/zoneinfo/


3、让android-2.3的galley支持bmp格式图片

修改ImageList.java文件,把ACCEPTABLE_IMAGE_TYPES改为:

private static final String[] ACCEPTABLE_IMAGE_TYPES =
            new String[] { "image/jpeg", "image/png", "image/gif", "image/x-ms-bmp", "image/vnd.wap.wbmp" };

把WHERE_CLAUSE改为:

private static final String WHERE_CLAUSE =
            "(" + Media.MIME_TYPE + " in (?, ?, ?, ?, ?))";


4、让android-2.3的mediascanner能扫描到乱码图片

修改external/jhead/main.c文件,在函数getAttributes中,把

for (k = 0; k < finalBufLen; k++)
        if (finalResult[k] > 127)
            finalResult[k] = '?';

改为

for (k = 0; k < finalBufLen; k++)
        if (finalResult[k] > 127 || finalResult[k]<0)
            finalResult[k] = '?';

5、去掉键盘锁

(1)修改frameworks/base/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java文件,把

private boolean mExternallyEnabled = true;

改为

private boolean mExternallyEnabled = false;

(2)修改frameworks/base/packages/SettingsProvider/res/values/defaults.xml文件,把

<integer name="def_screen_off_timeout">60000</integer>

改为

<integer name="def_screen_off_timeout">-1</integer>

原创粉丝点击