Android Open Source - TrafoControl Access Point






From Project

Back to project page TrafoControl.

License

The source code is released under:

MIT License

If you think the Android project TrafoControl 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

package com.bernhardeiling.trafocontrol.network;
//from  w ww.  j a  va  2s  . co  m
import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;

import com.bernhardeiling.trafocontrol.interfaces.ScanDevicesInterface;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by Bernhard on 21.08.14.
 */
public class AccessPoint extends Thread {

    private WifiManager wifiManager;
    private String ssid;
    private String password;

    public AccessPoint(Context context, String ssid, String password) {
        wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        this.ssid = ssid;
        this.password = password;
    }

    public void createAccessPoint() {

        if (wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(false);
        }

        Method[] managerMethods = wifiManager.getClass().getDeclaredMethods();

        for (Method method : managerMethods) {
            if (method.getName().equals("setWifiApEnabled")) {

                WifiConfiguration wifiConfiguration = new WifiConfiguration();
                wifiConfiguration.SSID = ssid;
                wifiConfiguration.wepKeys[0] = password;
                wifiConfiguration.wepTxKeyIndex = 0;
                wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); // NONE uses WEP

                try {
                    method.invoke(wifiManager, wifiConfiguration, true);
                }  catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }

            }
        }
    }

    public void scanForConnectedDevices(ScanDevicesInterface delegate) {
        ScanDevicesTask scanDevicesTask = new ScanDevicesTask(delegate);
        scanDevicesTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}




Java Source Code List

com.bernhardeiling.trafocontrol.ApplicationTest.java
com.bernhardeiling.trafocontrol.MainActivity.java
com.bernhardeiling.trafocontrol.animation.AnimationContainer.java
com.bernhardeiling.trafocontrol.animation.AnimationController.java
com.bernhardeiling.trafocontrol.animation.Animation.java
com.bernhardeiling.trafocontrol.animation.LoadAnimationThread.java
com.bernhardeiling.trafocontrol.animation.SyncAnimationThread.java
com.bernhardeiling.trafocontrol.interfaces.ScanDevicesInterface.java
com.bernhardeiling.trafocontrol.network.AccessPoint.java
com.bernhardeiling.trafocontrol.network.ScanDevicesTask.java