FileDocCategorySizeDatePackage
AndroidWifiDataProvider.javaAPI DocAndroid 1.5 API5029Wed May 06 22:41:56 BST 2009android.webkit.gears

AndroidWifiDataProvider

public final class AndroidWifiDataProvider extends android.content.BroadcastReceiver
WiFi data provider implementation for Android. {@hide}

Fields Summary
private static final String
TAG
Logging tag
private android.net.wifi.WifiManager
mWifiManager
Our Wifi manager instance.
private long
mNativeObject
The native object ID.
private android.content.Context
mContext
The 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 voidonReceive(android.content.Context context, android.content.Intent intent)
This method is called when the AndroidWifiDataProvider is receiving an Intent broadcast.

param
context The Context in which the receiver is running.
param
intent The Intent being received.

    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 voidonUpdateAvailable(java.util.List scanResults, long nativeObject)
The native method called when new wifi data is available.

param
scanResults is a list of ScanResults to pass to the native side.
param
nativeObject is a pointer to the corresponding AndroidWifiDataProvider C++ instance.

public voidshutdown()
Called when the provider is no longer needed.

    mContext.unregisterReceiver(this);
    if (Config.LOGV) {
      Log.v(TAG, "Wifi provider closed.");
    }