簡體   English   中英

如何在Android中使用NDK JNI獲得Wifi RSSI級別

[英]How to get Wifi RSSI level with NDK JNI in Android

有人有一個例子,或者可以顯示出如何通過Android中的NDK JNI獲得Wifi RSSI級別的方法嗎? 我必須比較Java代碼和JNI的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

這對我來說工作得很好。 那么,現在我該如何從其他庫中調用方法呢? 例如,我找到了Link1Link2 ,並對RSSI感興趣

該方法的輸入是發送到wifi驅動程序的命令。 嘗試:

res = android_net_wifi_getRssiHelper("SIGNAL_POLL");

要獲得對命令和響應的更多控制,可以通過以下方式手動發送命令:

doCommand(const char *cmd, char *replybuf, int replybuflen);

cmd是您的命令。

有關可用命令的列表,請參見:

https://android.googlesource.com/platform/frameworks/base/+/0e2d281/wifi/java/android/net/wifi/WifiNative.java

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM