PWD:/hardware/libhardware_legacy/test-liang 其中test-liang为新建目录 内容如下:
test-liang.c
Android.mk
test-liang.c:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
int main()
{
int length = 0;
FILE *fp;
char state[20];
memset(state, 0, sizeof(state));
system("wpa_cli status | busybox grep wpa_state | busybox cut -b 11- > /system/bin/liangyangang-test");
fp = fopen("/system/bin/liangyangang-test", "r");
if(NULL == fp)
{
printf("error112....");
exit(1);
}
fgets(state,20,fp);
fclose(fp);
length = strlen(state);
if(length == 10)
{
printf("COMPELED\n");
return 4;
} else if(length == 12)
{
printf("ASSOCIATING\n");
return 3;
} else if (length == 9)
{
printf("SCANNING\n");
return 2;
} else if (length == 13)
{
printf("DISCONNECTED\n");
return 1;
} else if(length == 0)
{
printf("wifi off\n");
return 0;
}
}
Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
test-liang.c
ifeq ($(TARGET_ARCH),arm)
LOCAL_SHARED_LIBRARIES += libdl
endif # arm
LOCAL_CFLAGS := -DRIL_SHLIB
LOCAL_MODULE:= test-liang
include $(BUILD_EXECUTABLE)
在编译android源码的时候可以直接编译这个文件