Gears Android WIFI/基站定位源代码分析
2010-03-18 16:11:00 来源:WEB开发网filter.addAction(mWifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
mContext.registerReceiver(this, filter, null, handler);
当收到WIFI扫描结果后,调用Native函数onUpdateAvailable,并把WIFI的扫描结果传递过去。
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(
mWifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
if (Config.LOGV) {
Log.v(TAG, "Wifi scan resulst available");
}
onUpdateAvailable(mWifiManager.getScanResults(), mNativeObject);
}
}
4.Native函数onUpdateAvailable是在wifi_data_provider_android.cc里实现的。
JNINativeMethod AndroidWifiDataProvider::native_methods_[] = {
{"onUpdateAvailable",
"(Ljava/util/List;J)V",
reinterpret_cast
},
};
void AndroidWifiDataProvider::OnUpdateAvailable(JNIEnv* ,
jclass ,
jobject wifi_data,
jlong self) {
assert(self);
AndroidWifiDataProvider *self_ptr =
reinterpret_cast(self);
WifiData new_wifi_data;
if (wifi_data) {
InitFromJava(wifi_data, &new_wifi_data);
}
// We notify regardless of whether new_wifi_data is empty
// or not. The arbitrator will decide what to do with an empty
// WifiData object.
self_ptr->NewWifiDataAvailable(&new_wifi_data);
}
void AndroidWifiDataProvider::NewWifiDataAvailable(WifiData* new_wifi_data) {
assert(supported_);
assert(new_wifi_data);
bool is_update_available = false;
data_mutex_.Lock();
is_update_available = wifi_data_.DiffersSignificantly(*new_wifi_data);
wifi_data_ = *new_wifi_data;
更多精彩
赞助商链接