AndroidWifiDataProviderpublic final class AndroidWifiDataProvider extends android.content.BroadcastReceiver WiFi data provider implementation for Android.
{@hide} |
Fields Summary |
---|
private static final String | TAGLogging tag | private android.net.wifi.WifiManager | mWifiManagerOur Wifi manager instance. | private long | mNativeObjectThe native object ID. | private android.content.Context | mContextThe Context instance. |
Constructors Summary |
---|
public AndroidWifiDataProvider(android.webkit.WebView webview, long object)Constructs a instance of this class and registers for wifi scan
updates. Note that this constructor must be called on a Looper
thread. Suitable threads can be created on the native side using
the AndroidLooperThread C++ class.
mNativeObject = object;
mContext = webview.getContext();
mWifiManager =
(WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
if (mWifiManager == null) {
Log.e(TAG,
"AndroidWifiDataProvider: could not get location manager.");
throw new NullPointerException(
"AndroidWifiDataProvider: locationManager is null.");
}
// Create a Handler that identifies the message loop associated
// with the current thread. Note that it is not necessary to
// override handleMessage() at all since the Intent
// ReceiverDispatcher (see the ActivityThread class) only uses
// this handler to post a Runnable to this thread's loop.
Handler handler = new Handler(Looper.myLooper());
IntentFilter filter = new IntentFilter();
filter.addAction(mWifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
mContext.registerReceiver(this, filter, null, handler);
// Get the last scan results and pass them to the native side.
// We can't just invoke the callback here, so we queue a message
// to this thread's loop.
handler.post(new Runnable() {
public void run() {
onUpdateAvailable(mWifiManager.getScanResults(), mNativeObject);
}
});
|
Methods Summary |
---|
public void | onReceive(android.content.Context context, android.content.Intent intent)This method is called when the AndroidWifiDataProvider is receiving an
Intent broadcast.
if (intent.getAction().equals(
mWifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
if (Config.LOGV) {
Log.v(TAG, "Wifi scan resulst available");
}
onUpdateAvailable(mWifiManager.getScanResults(), mNativeObject);
}
| private static native void | onUpdateAvailable(java.util.List scanResults, long nativeObject)The native method called when new wifi data is available.
| public void | shutdown()Called when the provider is no longer needed.
mContext.unregisterReceiver(this);
if (Config.LOGV) {
Log.v(TAG, "Wifi provider closed.");
}
|
|