如何在Android中使用NDK JNI获取Wifi RSSI级别
问题描述:
是否有人有示例或可以显示它如何在Android中使用NDK JNI获取Wifi RSSI级别? 我必须比较java代码vs JNI的rssi级别。如何在Android中使用NDK JNI获取Wifi RSSI级别
在此先感谢!
UPDATE
我现在能够得到从CPP文件中的字符串。
文件: com_example_cvlab_ndktest_NativeClass.cpp
#include <com_example_cvlab_ndktest_NativeClass.h>
JNIEXPORT jstring JNICALL
Java_com_example_cvlab_ndktest_NativeClass_getMessageFromJNI
(JNIEnv *env, jclass obj){
return env->NewStringUTF("This is a message from JNI");
}
com_example_cvlab_ndktest_NativeClass.h:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_example_cvlab_ndktest_NativeClass */
#ifndef _Included_com_example_cvlab_ndktest_NativeClass
#define _Included_com_example_cvlab_ndktest_NativeClass
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_example_cvlab_ndktest_NativeClass
* Method: getMessageFromJNI
* Signature:()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_com_example_cvlab_ndktest_NativeClass_getMessageFromJNI
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
NativeClass.java 包com.example.cvlab.ndktest;
/**
* Created by zafaco on 14.06.2017.
*/
public class NativeClass {
public native static String getMessageFromJNI();
}
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := com_example_cvlab_ndktest_NativeClass.cpp
LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyLibs
include $(BUILD_SHARED_LIBRARY)
Application.mk:
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-16
答
该方法的输入是要发送到WiFi驱动程序的命令。尝试:
res = android_net_wifi_getRssiHelper("SIGNAL_POLL");
,并得到了命令和响应更多的控制,你可以通过手动发送命令:
doCommand(const char *cmd, char *replybuf, int replybuflen);
其中cmd
是你的命令。
对于可能的命令的列表,你可以用看:
我试图解析度= android_net_wifi_getRssiHelper( “SIGNAL_POLL”);我得到这个错误:无法解析方法'android_net_wifi_getRssiHelper(java.lang.String)' –
这是一个本地方法,你应该在c中使用。你在找java api吗? – SoroushA
没有抱歉。你是对的。当我再回到家时,我会尝试它。谢谢你到目前为止! –