关闭

Android手机通过wifi进行数据传输(三)

256人阅读 评论(0) 收藏 举报
分类:
 源码文件2
MyTimerCheck.java
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="kwd" style="color: rgb(0, 0, 136);">package</span><span class="pln"> edu</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">cdut</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">robin</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">hotspot</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div>
</div><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">abstract</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MyTimerCheck</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> mCount </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> mTimeOutCount </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">int</span><span class="pln"> mSleepTime </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="lit" style="color: rgb(0, 102, 102);">1000</span><span class="pun" style="color: rgb(102, 102, 0);">;</span><span class="pln"> </span><span class="com" style="color: rgb(136, 0, 0);">// 1s</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private boolean mExitFlag = false;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private Thread mThread = null;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    /**</span></div><div><span class="com" style="color: rgb(136, 0, 0);">     * Do not process UI work in this.</span></div><div><span class="com" style="color: rgb(136, 0, 0);">     */</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public abstract void doTimerCheckWork();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public abstract void doTimeOutWork();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public MyTimerCheck() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mThread = new Thread(new Runnable() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            </span></div><div><span class="com" style="color: rgb(136, 0, 0);">            @Override</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            public void run() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                // TODO Auto-generated method stub</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                while (!mExitFlag) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    mCount++;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    if (mCount < mTimeOutCount) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                        doTimerCheckWork();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                        try {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                            mThread.sleep(mSleepTime);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                        } catch (InterruptedException e) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                            // TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                            e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                            exit();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    } else {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                        doTimeOutWork();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        });</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    /**</span></div><div><span class="com" style="color: rgb(136, 0, 0);">     * start</span></div><div><span class="com" style="color: rgb(136, 0, 0);">     * @param times  How many times will check?</span></div><div><span class="com" style="color: rgb(136, 0, 0);">     * @param sleepTime ms, Every check sleep time.</span></div><div><span class="com" style="color: rgb(136, 0, 0);">     */</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public void start(int timeOutCount, int sleepTime) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mTimeOutCount = timeOutCount;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mSleepTime = sleepTime;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mThread.start();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public void exit() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mExitFlag = true;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">}</span></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
源码文件3
WifiAdmin.java
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><div><span class="kwd" style="color: rgb(0, 0, 136);">package</span><span class="pln"> edu</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">cdut</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">robin</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">hotspot</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> java</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">util</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">List</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> java</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">util</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Timer</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> java</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">util</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">TimerTask</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">content</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">BroadcastReceiver</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">content</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Context</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">content</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">content</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">IntentFilter</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">net</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">ConnectivityManager</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">net</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">NetworkInfo</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">net</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">NetworkInfo</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">DetailedState</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">net</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">wifi</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">ScanResult</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">net</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">wifi</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">net</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">wifi</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">WifiInfo</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">net</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">wifi</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">WifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">net</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">wifi</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">WifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">WifiLock</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">util</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Log</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div>
</div><div>
</div><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">abstract</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">WifiAdmin</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">static</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">final</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> TAG </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="str" style="color: rgb(0, 136, 0);">"WifiAdmin"</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">WifiManager</span><span class="pln"> mWifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">WifiInfo</span><span class="pln"> mWifiInfo</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 扫描出的网络连接列表</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private List<ScanResult> mWifiList;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private List<WifiConfiguration> mWifiConfiguration;</span></div><div>
</div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">WifiLock</span><span class="pln"> mWifiLock</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> mPasswd </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="str" style="color: rgb(0, 136, 0);">""</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> mSSID </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="str" style="color: rgb(0, 136, 0);">""</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Context</span><span class="pln"> mContext </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">null</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div>
</div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">WifiAdmin</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Context</span><span class="pln"> context</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">        </span></div><div><span class="pln">        mContext </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> context</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">        </span></div><div><span class="pln">        </span><span class="com" style="color: rgb(136, 0, 0);">// 取得WifiManager对象</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        // 取得WifiInfo对象</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mWifiInfo = mWifiManager.getConnectionInfo();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        Log.v(TAG, "getIpAddress = " + mWifiInfo.getIpAddress());</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 打开WIFI</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public void openWifi() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        if (!mWifiManager.isWifiEnabled()) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            mWifiManager.setWifiEnabled(true);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 关闭WIFI</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public void closeWifi() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        if (mWifiManager.isWifiEnabled()) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            mWifiManager.setWifiEnabled(false);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">abstract</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pln"> myRegisterReceiver</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">BroadcastReceiver</span><span class="pln"> receiver</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">IntentFilter</span><span class="pln"> filter</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">abstract</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> myUnregisterReceiver</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">BroadcastReceiver</span><span class="pln"> receiver</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">abstract</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> onNotifyWifiConnected</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">abstract</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> onNotifyWifiConnectFailed</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 添加一个网络并连接</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public void addNetwork(WifiConfiguration wcg) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        register();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        WifiApAdmin.closeWifiAp(mContext);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        int wcgID = mWifiManager.addNetwork(wcg);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        boolean b = mWifiManager.enableNetwork(wcgID, true);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public static final int TYPE_NO_PASSWD = 0x11;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public static final int TYPE_WEP = 0x12;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public static final int TYPE_WPA = 0x13;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public void addNetwork(String ssid, String passwd, int type) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        if (ssid == null || passwd == null || ssid.equals("")) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            Log.e(TAG, "addNetwork() ## nullpointer error!");</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            return;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        if (type != TYPE_NO_PASSWD && type != TYPE_WEP && type != TYPE_WPA) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            Log.e(TAG, "addNetwork() ## unknown type = " + type);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        stopTimer();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        unRegister();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        addNetwork(createWifiInfo(ssid, passwd, type));</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">BroadcastReceiver</span><span class="pln"> mBroadcastReceiver </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">BroadcastReceiver</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div>
</div><div><span class="pln">        </span><span class="lit" style="color: rgb(0, 102, 102);">@Override</span></div><div><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> onReceive</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Context</span><span class="pln"> context</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Intent</span><span class="pln"> intent</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            </span><span class="com" style="color: rgb(136, 0, 0);">// TODO Auto-generated method stub</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            if (intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                Log.d(TAG, "RSSI changed");</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                </span></div><div><span class="com" style="color: rgb(136, 0, 0);">                //有可能是正在获取,或者已经获取了</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                Log.d(TAG, " intent is " + WifiManager.RSSI_CHANGED_ACTION);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                </span></div><div><span class="com" style="color: rgb(136, 0, 0);">                if (isWifiContected(mContext) == WIFI_CONNECTED) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    stopTimer();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    onNotifyWifiConnected();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    unRegister();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                } else if (isWifiContected(mContext) == WIFI_CONNECT_FAILED) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    stopTimer();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    closeWifi();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    onNotifyWifiConnectFailed();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    unRegister();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                } else if (isWifiContected(mContext) == WIFI_CONNECTING) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">                }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    };</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private final int STATE_REGISTRING = 0x01;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private final int STATE_REGISTERED = 0x02;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private final int STATE_UNREGISTERING = 0x03;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private final int STATE_UNREGISTERED = 0x04;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private int mHaveRegister = STATE_UNREGISTERED;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private synchronized void register() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        Log.v(TAG, "register() ##mHaveRegister = " + mHaveRegister);</span></div><div>
</div><div><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">if</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">mHaveRegister </span><span class="pun" style="color: rgb(102, 102, 0);">==</span><span class="pln"> STATE_REGISTRING </span></div><div><span class="pln">                </span><span class="pun" style="color: rgb(102, 102, 0);">||</span><span class="pln"> mHaveRegister </span><span class="pun" style="color: rgb(102, 102, 0);">==</span><span class="pln"> STATE_REGISTERED</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            </span><span class="kwd" style="color: rgb(0, 0, 136);">return</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">        </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln">        </span></div><div><span class="pln">        mHaveRegister </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> STATE_REGISTRING</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">        myRegisterReceiver</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">mBroadcastReceiver</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">IntentFilter</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">RSSI_CHANGED_ACTION</span><span class="pun" style="color: rgb(102, 102, 0);">));</span></div><div><span class="pln">        mHaveRegister </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> STATE_REGISTERED</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">        </span></div><div><span class="pln">        startTimer</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">    </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">synchronized</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> unRegister</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">        </span><span class="typ" style="color: rgb(102, 0, 102);">Log</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">v</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">TAG</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="str" style="color: rgb(0, 136, 0);">"unRegister() ##mHaveRegister = "</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="pln"> mHaveRegister</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">        </span></div><div><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">if</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">mHaveRegister </span><span class="pun" style="color: rgb(102, 102, 0);">==</span><span class="pln"> STATE_UNREGISTERED </span></div><div><span class="pln">                </span><span class="pun" style="color: rgb(102, 102, 0);">||</span><span class="pln"> mHaveRegister </span><span class="pun" style="color: rgb(102, 102, 0);">==</span><span class="pln"> STATE_UNREGISTERING</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            </span><span class="kwd" style="color: rgb(0, 0, 136);">return</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">        </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln">        </span></div><div><span class="pln">        mHaveRegister </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> STATE_UNREGISTERING</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">        myUnregisterReceiver</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">mBroadcastReceiver</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">        mHaveRegister </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> STATE_UNREGISTERED</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Timer</span><span class="pln"> mTimer </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">null</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> startTimer</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">if</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">mTimer </span><span class="pun" style="color: rgb(102, 102, 0);">!=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">null</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            stopTimer</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">        </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln">        </span></div><div><span class="pln">        mTimer </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Timer</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">true</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">//      mTimer.schedule(mTimerTask, 0, 20 * 1000);// 20s</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mTimer.schedule(mTimerTask, 30 * 1000);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private TimerTask mTimerTask = new TimerTask() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        @Override</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        public void run() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            // TODO Auto-generated method stub</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            Log.e(TAG, "timer out!");</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            onNotifyWifiConnectFailed();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            unRegister();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    };</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private void stopTimer() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        if (mTimer != null) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            mTimer.cancel();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            mTimer = null;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    @Override</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    protected void finalize() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        try {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            super.finalize();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            unRegister();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        } catch (Throwable e) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            // TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public WifiConfiguration createWifiInfo(String SSID, String password, int type) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        Log.v(TAG, "SSID = " + SSID + "## Password = " + password + "## Type = " + type);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        WifiConfiguration config = new WifiConfiguration();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        config.allowedAuthAlgorithms.clear();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        config.allowedGroupCiphers.clear();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        config.allowedKeyManagement.clear();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        config.allowedPairwiseCiphers.clear();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        config.allowedProtocols.clear();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        config.SSID = "\"" + SSID + "\"";</span></div><div>
</div><div><span class="pln">        </span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pln"> tempConfig </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">this</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">IsExsits</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">SSID</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">if</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">tempConfig </span><span class="pun" style="color: rgb(102, 102, 0);">!=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">null</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            mWifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">removeNetwork</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">tempConfig</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">networkId</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">        </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln">        </span></div><div><span class="pln">        </span><span class="com" style="color: rgb(136, 0, 0);">// 分为三种情况:1没有密码2用wep加密3用wpa加密</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        if (type == TYPE_NO_PASSWD) {// WIFICIPHER_NOPASS</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.wepKeys[0] = "";</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.wepTxKeyIndex = 0;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        } else if (type == TYPE_WEP) {  //  WIFICIPHER_WEP </span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.hiddenSSID = true;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.wepKeys[0] = "\"" + password + "\"";</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedAuthAlgorithms</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    .set(WifiConfiguration.AuthAlgorithm.SHARED);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedGroupCiphers</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    .set(WifiConfiguration.GroupCipher.WEP104);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.wepTxKeyIndex = 0;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        } else if (type == TYPE_WPA) {   // WIFICIPHER_WPA</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.preSharedKey = "\"" + password + "\"";</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.hiddenSSID = true;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedAuthAlgorithms</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    .set(WifiConfiguration.AuthAlgorithm.OPEN);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedPairwiseCiphers</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    .set(WifiConfiguration.PairwiseCipher.TKIP);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            // config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.allowedPairwiseCiphers</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    .set(WifiConfiguration.PairwiseCipher.CCMP);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            config.status = WifiConfiguration.Status.ENABLED;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        } </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        return config;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public static final int WIFI_CONNECTED = 0x01;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public static final int WIFI_CONNECT_FAILED = 0x02;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public static final int WIFI_CONNECTING = 0x03;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    /**</span></div><div><span class="com" style="color: rgb(136, 0, 0);">     * 判断wifi是否连接成功,不是network</span></div><div><span class="com" style="color: rgb(136, 0, 0);">     * </span></div><div><span class="com" style="color: rgb(136, 0, 0);">     * @param context</span></div><div><span class="com" style="color: rgb(136, 0, 0);">     * @return</span></div><div><span class="com" style="color: rgb(136, 0, 0);">     */</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public int isWifiContected(Context context) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        ConnectivityManager connectivityManager = (ConnectivityManager) context</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                .getSystemService(Context.CONNECTIVITY_SERVICE);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        NetworkInfo wifiNetworkInfo = connectivityManager</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                .getNetworkInfo(ConnectivityManager.TYPE_WIFI);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">        Log.v(TAG, "isConnectedOrConnecting = " + wifiNetworkInfo.isConnectedOrConnecting());</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        Log.d(TAG, "wifiNetworkInfo.getDetailedState() = " + wifiNetworkInfo.getDetailedState());</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        if (wifiNetworkInfo.getDetailedState() == DetailedState.OBTAINING_IPADDR</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                || wifiNetworkInfo.getDetailedState() == DetailedState.CONNECTING) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            return WIFI_CONNECTING;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        } else if (wifiNetworkInfo.getDetailedState() == DetailedState.CONNECTED) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            return WIFI_CONNECTED;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        } else {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            Log.d(TAG, "getDetailedState() == " + wifiNetworkInfo.getDetailedState());</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            return WIFI_CONNECT_FAILED;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    private WifiConfiguration IsExsits(String SSID) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        List<WifiConfiguration> existingConfigs = mWifiManager.getConfiguredNetworks();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        for (WifiConfiguration existingConfig : existingConfigs) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            if (existingConfig.SSID.equals("\"" + SSID + "\"") /*&& existingConfig.preSharedKey.equals("\"" + password + "\"")*/) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                return existingConfig;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        return null;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 断开指定ID的网络</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public void disconnectWifi(int netId) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mWifiManager.disableNetwork(netId);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mWifiManager.disconnect();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    // 检查当前WIFI状态</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public int checkState() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        return mWifiManager.getWifiState();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 锁定WifiLock</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public void acquireWifiLock() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mWifiLock.acquire();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 解锁WifiLock</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public void releaseWifiLock() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        // 判断时候锁定</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        if (mWifiLock.isHeld()) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            mWifiLock.acquire();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 创建一个WifiLock</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public void creatWifiLock() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mWifiLock = mWifiManager.createWifiLock("Test");</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 得到配置好的网络</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public List<WifiConfiguration> getConfiguration() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        return mWifiConfiguration;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 指定配置好的网络进行连接</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public void connectConfiguration(int index) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        // 索引大于配置好的网络索引返回</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        if (index > mWifiConfiguration.size()) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            return;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        // 连接配置好的指定ID的网络</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        mWifiManager.enableNetwork(mWifiConfiguration.get(index).networkId,</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                true);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> startScan</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">        mWifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">startScan</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">        mWifiList </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> mWifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getScanResults</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">        mWifiConfiguration </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> mWifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getConfiguredNetworks</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">    </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 得到网络列表</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public List<ScanResult> getWifiList() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        return mWifiList;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 查看扫描结果</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public StringBuilder lookUpScan() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        StringBuilder stringBuilder = new StringBuilder();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        for (int i = 0; i < mWifiList.size(); i++) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            stringBuilder</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    .append("Index_" + new Integer(i + 1).toString() + ":");</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            // 将ScanResult信息转换成一个字符串包</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            // 其中把包括:BSSID、SSID、capabilities、frequency、level</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            stringBuilder.append((mWifiList.get(i)).toString());</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            stringBuilder.append("/n");</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        return stringBuilder;</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 得到MAC地址</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public String getMacAddress() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        return (mWifiInfo == null) ? "NULL" : mWifiInfo.getMacAddress();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 得到接入点的BSSID</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public String getBSSID() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        return (mWifiInfo == null) ? "NULL" : mWifiInfo.getBSSID();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 得到IP地址</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public int getIPAddress() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        return (mWifiInfo == null) ? 0 : mWifiInfo.getIpAddress();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 得到连接的ID</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public int getNetworkId() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        return (mWifiInfo == null) ? 0 : mWifiInfo.getNetworkId();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="com" style="color: rgb(136, 0, 0);">// 得到WifiInfo的所有信息包</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    public String getWifiInfo() {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        return (mWifiInfo == null) ? "NULL" : mWifiInfo.toString();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">}</span></div></div><div></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
源码文件4
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p><div><span class="typ" style="color: rgb(102, 0, 102);">WifiApAdmin</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">java</span></div><div><div><span class="pln">package edu</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">cdut</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">robin</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">hotspot</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div>
</div><div>
</div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> java</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">lang</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">reflect</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">InvocationTargetException</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> java</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">lang</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">reflect</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Method</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> java</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">util</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Timer</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> java</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">util</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">TimerTask</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div>
</div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">content</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Context</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">net</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">wifi</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">net</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">wifi</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">WifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">import</span><span class="pln"> android</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">util</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Log</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div>
</div><div><span class="com" style="color: rgb(136, 0, 0);">/**</span></div><div><span class="com" style="color: rgb(136, 0, 0);"> * 创建热点</span></div><div><span class="com" style="color: rgb(136, 0, 0);"> *</span></div><div><span class="com" style="color: rgb(136, 0, 0);"> */</span></div><div><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">WifiApAdmin</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">static</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">final</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> TAG </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="str" style="color: rgb(0, 136, 0);">"WifiApAdmin"</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">static</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> closeWifiAp</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Context</span><span class="pln"> context</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">        </span><span class="typ" style="color: rgb(102, 0, 102);">WifiManager</span><span class="pln"> wifiManager </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> context</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getSystemService</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Context</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">WIFI_SERVICE</span><span class="pun" style="color: rgb(102, 102, 0);">);</span><span class="pln"> </span></div><div><span class="pln">        closeWifiAp</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">wifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">    </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">WifiManager</span><span class="pln"> mWifiManager </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">null</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">Context</span><span class="pln"> mContext </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">null</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">WifiApAdmin</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Context</span><span class="pln"> context</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">        mContext </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> context</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">        </span></div><div><span class="pln">        mWifiManager </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> mContext</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getSystemService</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Context</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">WIFI_SERVICE</span><span class="pun" style="color: rgb(102, 102, 0);">);</span><span class="pln">  </span></div><div><span class="pln">        </span></div><div><span class="pln">        closeWifiAp</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">mWifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">    </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div><span class="pln">    </span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> mSSID </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="str" style="color: rgb(0, 136, 0);">""</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> mPasswd </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="str" style="color: rgb(0, 136, 0);">""</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> startWifiAp</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> ssid</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">String</span><span class="pln"> passwd</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">        mSSID </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> ssid</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">        mPasswd </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> passwd</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">        </span></div><div><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">if</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">mWifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">isWifiEnabled</span><span class="pun" style="color: rgb(102, 102, 0);">())</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            mWifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">setWifiEnabled</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">false</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">        </span><span class="pun" style="color: rgb(102, 102, 0);">}</span><span class="pln"> </span></div><div><span class="pln">        </span></div><div><span class="pln">        stratWifiAp</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div><span class="pln">        </span></div><div><span class="pln">        </span><span class="typ" style="color: rgb(102, 0, 102);">MyTimerCheck</span><span class="pln"> timerCheck </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">MyTimerCheck</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            </span></div><div><span class="pln">            </span><span class="lit" style="color: rgb(0, 102, 102);">@Override</span></div><div><span class="pln">            </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> doTimerCheckWork</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">                </span><span class="com" style="color: rgb(136, 0, 0);">// TODO Auto-generated method stub</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                </span></div><div><span class="com" style="color: rgb(136, 0, 0);">                if (isWifiApEnabled(mWifiManager)) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    Log.v(TAG, "Wifi enabled success!");</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    this.exit();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                } else {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                    Log.v(TAG, "Wifi enabled failed!");</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            }</span></div><div>
</div><div><span class="pln">            </span><span class="lit" style="color: rgb(0, 102, 102);">@Override</span></div><div><span class="pln">            </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> doTimeOutWork</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">                </span><span class="com" style="color: rgb(136, 0, 0);">// TODO Auto-generated method stub</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                this.exit();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        };</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        timerCheck.start(15, 1000);</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        </span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">public</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> stratWifiAp</span><span class="pun" style="color: rgb(102, 102, 0);">()</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">        </span><span class="typ" style="color: rgb(102, 0, 102);">Method</span><span class="pln"> method1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">null</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">try</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            method1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> mWifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getClass</span><span class="pun" style="color: rgb(102, 102, 0);">().</span><span class="pln">getMethod</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"setWifiApEnabled"</span><span class="pun" style="color: rgb(102, 102, 0);">,</span></div><div><span class="pln">                    </span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">boolean</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">            </span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pln"> netConfig </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">new</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">();</span></div><div>
</div><div><span class="pln">            netConfig</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">SSID </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> mSSID</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">            netConfig</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">preSharedKey </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> mPasswd</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div>
</div><div><span class="pln">            netConfig</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">allowedAuthAlgorithms</span></div><div><span class="pln">                    </span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">set</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">AuthAlgorithm</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">OPEN</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">            netConfig</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">allowedProtocols</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">set</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Protocol</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">RSN</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">            netConfig</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">allowedProtocols</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">set</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">Protocol</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">WPA</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">            netConfig</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">allowedKeyManagement</span></div><div><span class="pln">                    </span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">set</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">KeyMgmt</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">WPA_PSK</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">            netConfig</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">allowedPairwiseCiphers</span></div><div><span class="pln">                    </span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">set</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">PairwiseCipher</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">CCMP</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">            netConfig</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">allowedPairwiseCiphers</span></div><div><span class="pln">                    </span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">set</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">PairwiseCipher</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">TKIP</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">            netConfig</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">allowedGroupCiphers</span></div><div><span class="pln">                    </span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">set</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">GroupCipher</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">CCMP</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">            netConfig</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">allowedGroupCiphers</span></div><div><span class="pln">                    </span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">set</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="typ" style="color: rgb(102, 0, 102);">GroupCipher</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">TKIP</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div>
</div><div><span class="pln">            method1</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">invoke</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">mWifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> netConfig</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">true</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div>
</div><div><span class="pln">        </span><span class="pun" style="color: rgb(102, 102, 0);">}</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">catch</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">IllegalArgumentException</span><span class="pln"> e</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            </span><span class="com" style="color: rgb(136, 0, 0);">// TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        } catch (IllegalAccessException e) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            // TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        } catch (InvocationTargetException e) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            // TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        } catch (SecurityException e) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            // TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        } catch (NoSuchMethodException e) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            // TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">static</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">void</span><span class="pln"> closeWifiAp</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiManager</span><span class="pln"> wifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">if</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">isWifiApEnabled</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">wifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">))</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            </span><span class="kwd" style="color: rgb(0, 0, 136);">try</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">                </span><span class="typ" style="color: rgb(102, 0, 102);">Method</span><span class="pln"> method </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> wifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getClass</span><span class="pun" style="color: rgb(102, 102, 0);">().</span><span class="pln">getMethod</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"getWifiApConfiguration"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">                method</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">setAccessible</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">true</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div>
</div><div><span class="pln">                </span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pln"> config </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> method</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">invoke</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">wifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div>
</div><div><span class="pln">                </span><span class="typ" style="color: rgb(102, 0, 102);">Method</span><span class="pln"> method2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> wifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getClass</span><span class="pun" style="color: rgb(102, 102, 0);">().</span><span class="pln">getMethod</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"setWifiApEnabled"</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">WifiConfiguration</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">boolean</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="kwd" style="color: rgb(0, 0, 136);">class</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">                method2</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">invoke</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">wifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> config</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">false</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">            </span><span class="pun" style="color: rgb(102, 102, 0);">}</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">catch</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">NoSuchMethodException</span><span class="pln"> e</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">                </span><span class="com" style="color: rgb(136, 0, 0);">// TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            } catch (IllegalArgumentException e) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                // TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            } catch (IllegalAccessException e) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                // TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            } catch (InvocationTargetException e) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                // TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">                e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div><span class="com" style="color: rgb(136, 0, 0);">    }</span></div><div>
</div><div><span class="pln">    </span><span class="kwd" style="color: rgb(0, 0, 136);">private</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">static</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">boolean</span><span class="pln"> isWifiApEnabled</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">WifiManager</span><span class="pln"> wifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">try</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            </span><span class="typ" style="color: rgb(102, 0, 102);">Method</span><span class="pln"> method </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> wifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">getClass</span><span class="pun" style="color: rgb(102, 102, 0);">().</span><span class="pln">getMethod</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="str" style="color: rgb(0, 136, 0);">"isWifiApEnabled"</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">            method</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">setAccessible</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="kwd" style="color: rgb(0, 0, 136);">true</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div><span class="pln">            </span><span class="kwd" style="color: rgb(0, 0, 136);">return</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">Boolean</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> method</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">invoke</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">wifiManager</span><span class="pun" style="color: rgb(102, 102, 0);">);</span></div><div>
</div><div><span class="pln">        </span><span class="pun" style="color: rgb(102, 102, 0);">}</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">catch</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="typ" style="color: rgb(102, 0, 102);">NoSuchMethodException</span><span class="pln"> e</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">{</span></div><div><span class="pln">            </span><span class="com" style="color: rgb(136, 0, 0);">// TODO Auto-generated catch block</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        } catch (Exception e) {</span></div><div><span class="com" style="color: rgb(136, 0, 0);">            e.printStackTrace();</span></div><div><span class="com" style="color: rgb(136, 0, 0);">        }</span></div><div>
</div><div><span class="pln">        </span><span class="kwd" style="color: rgb(0, 0, 136);">return</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">false</span><span class="pun" style="color: rgb(102, 102, 0);">;</span></div><div><span class="pln">    </span><span class="pun" style="color: rgb(102, 102, 0);">}</span></div><div>
</div><div><span class="pun" style="color: rgb(102, 102, 0);">}</span></div></div><div></div><p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;"></p>
下文
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:41241次
    • 积分:779
    • 等级:
    • 排名:千里之外
    • 原创:15篇
    • 转载:128篇
    • 译文:0篇
    • 评论:0条
    文章分类
    最新评论