Android Open Source - Android-Wifi-Hotspot-Manager-Class Main






From Project

Back to project page Android-Wifi-Hotspot-Manager-Class.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCT...

If you think the Android project Android-Wifi-Hotspot-Manager-Class listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2013 WhiteByte (Nick Russler, Ahmet Yueksektepe).
 */*from  www. ja va2 s.c  om*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.whitebyte.hotspotcontrolexample;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.whitebyte.hotspotclients.R;
import com.whitebyte.wifihotspotutils.ClientScanResult;
import com.whitebyte.wifihotspotutils.FinishScanListener;
import com.whitebyte.wifihotspotutils.WifiApManager;

public class Main extends Activity {
  TextView textView1;
  WifiApManager wifiApManager; 

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    textView1 = (TextView) findViewById(R.id.textView1);
    wifiApManager = new WifiApManager(this);

    scan();

  }

  private void scan() {
    wifiApManager.getClientList(false, new FinishScanListener() {

      @Override
      public void onFinishScan(final ArrayList<ClientScanResult> clients) {

        textView1.setText("WifiApState: " + wifiApManager.getWifiApState() + "\n\n");
        textView1.append("Clients: \n");
        for (ClientScanResult clientScanResult : clients) {
          textView1.append("####################\n");
          textView1.append("IpAddr: " + clientScanResult.getIpAddr() + "\n");
          textView1.append("Device: " + clientScanResult.getDevice() + "\n");
          textView1.append("HWAddr: " + clientScanResult.getHWAddr() + "\n");
          textView1.append("isReachable: " + clientScanResult.isReachable() + "\n");
        }
      }
    });
  }

  public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, 0, 0, "Get Clients");
    menu.add(0, 1, 0, "Open AP");
    menu.add(0, 2, 0, "Close AP");
    return super.onCreateOptionsMenu(menu);
  }

  public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch (item.getItemId()) {
    case 0:
      scan();
      break;
    case 1:
      wifiApManager.setWifiApEnabled(null, true);
      break;
    case 2:
      wifiApManager.setWifiApEnabled(null, false);
      break;
    }

    return super.onMenuItemSelected(featureId, item);
  }
}




Java Source Code List

com.whitebyte.hotspotcontrolexample.Main.java
com.whitebyte.wifihotspotutils.ClientScanResult.java
com.whitebyte.wifihotspotutils.FinishScanListener.java
com.whitebyte.wifihotspotutils.WIFI_AP_STATE.java
com.whitebyte.wifihotspotutils.WifiApManager.java