Test the android driver by JNI (Java Native Interface),

  In the third article, we know how to compiler the moduler for localhost, ok6410 and goldfish platform.

http://www.cnblogs.com/plinx/p/3209500.html

  But we didn't try to test the driver using by C/C++ program on ok6410 and goldfish.

  Android was changing from linux, so there must remain some fetures linux working.

  If we want to test a driver using C/C++ program, we should get ready for the following conditions :

  (1) Goldfish emulator/Ok6410/Phone must got the permission to "root".

  (2) The exec file compiled by the cross compiler.

  It's easy to go on within these limits, we just need to compile the C/C++ program in the android source configured by "Android.mk".

  

  Here is the Android.mk :

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)# files to compilerLOCAL_SRC_FILES := ftest.c# obj name - the output execute file nameLOCAL_MODULE := ftestLOCAL_MODULE_TAGS := optionalinclude $(BUILD_EXECUTABLE)

  And the ftest.c is :

#include <stdio.h>#include <fcntl.h>#include <unistd.h>#include <stdlib.h>#include <string.h>int main(int argc, char *argv[]){    int testdev;    int ret;    int num = 0;    unsigned char buf[4];    testdev = open("/dev/wordcount2", O_RDWR);    if(testdev == -1) {        printf("Can not open file.\n");        return 0;    }    if(argc > 1) {        printf("Strings : %s.\n", argv[1]);        write(testdev, argv[1], strlen(argv[1]));    }    read(testdev, buf, 4);    num =     ((int)buf[0]) << 24 | \        ((int)buf[1]) << 16 | \        ((int)buf[2]) << 8  | \        ((int)buf[3]);    printf("Word Byte : 0x%d%d%d%dH\n", buf[0], buf[1], buf[2], buf[3]);    printf("word count: %d\n", num);    close(testdev);    return 0;}

  now, we should mkdir in the source code :

$ pwd~/Android/source_code/development/ndk/wordcount$ lsAndroid.mk  ftest.c

  then return to the root directory :

$ cd ~/Android/source_code/$ source build/envsetup.sh$ mmm development/ndk/wordcount...Install: out/target/product/generic/system/bin/ftest...

  Then we just need to push the file to emulator and test it.

    

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 我的android 第7天 - 控件美化 和 编码性
  2. Android动画之RotateAnimation使用
  3. ERROR: Unknown command 'crunch'
  4. android反编译工具(ApkDec-Release-0.1)-正
  5. Android详细教程 - 基础篇完成了
  6. android Shape使用
  7. android webkit学习笔记1---url的load过
  8. android软键盘弹出,会把原来的界面挤上去
  9. Android(安卓)ListView优化之getView频繁
  10. Android(安卓)之 shape和selector用法介