码迷,mamicode.com
首页 > 其他好文 > 详细

方便快捷管理wifi

时间:2015-01-17 18:12:17      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:

本应用是完全免费的,目的是方便用户管理wifi,方便、快捷,而不用进“系统设置”去查找“无线网络”设置菜单。点击应用后,帮助用户打开wifi开关,并可扫描附近wifi热点、显示给用户,当用户点击其中一个wifi热点,跳转到用户输入密码的界面,输入密码确定后,自动连接wifi。

[1].[文件] WifiManager.zip ~ 941KB    下载(172) 跳至 [1] [2] [3] [4] [5] [6] [7]

[2].[文件] Wifi便捷管理.apk ~ 188KB    下载(61) 跳至 [1] [2] [3] [4] [5] [6] [7]

[3].[代码] [Java]代码 跳至 [1] [2] [3] [4] [5] [6] [7]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.syl.wifimanager;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
 
public class MainActivity extends Activity {
    private static final String LOG_TAG = "NETWORK_WifiFirstActivity";
    private WifiAdmin mWifiAdmin;
    private List<ScanResult> list;
    private ScanResult mScanResult;
    private ListView localList;
    private Button freshBT;
    private ArrayList<HashMap<String, Object>> localWifi;
    private SimpleAdapter adapter;
    private WifiReceiver wifiReceiver;
    private Handler wifiHandler;
    private static final int MSG_ID_STOP_SCAN = 100;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initMainUI();
    }
     
    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
    }
 
    protected void onDestroy() {
        super.onDestroy();
    }
     
    private void initMainUI() {
        setContentView(R.layout.wifi_ssid_display);
        localList = (ListView)findViewById(R.id.local_list);
        mWifiAdmin = new WifiAdmin(MainActivity.this);
        localWifi = new ArrayList<HashMap<String,Object>>();
        wifiReceiver = new WifiReceiver();             
        freshBT = (Button)findViewById(R.id.wifiFresh);
        wifiHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                // TODO Auto-generated method stub
                super.handleMessage(msg);
                switch(msg.what) {
                case MSG_ID_STOP_SCAN:                 
                    if (wifiReceiver != null) {
                        MainActivity.this.unregisterReceiver(wifiReceiver);
                        Log.i(LOG_TAG, "stop scan wifi");
                    }
                    break;
                }
            }
        };
        if (freshBT != null) {
            freshBT.setOnClickListener(new MyOnClickListener());
        }      
        getLocalWifiSsid();
        MainActivity.this.registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    }
 
    private void getLocalWifiSsid() {
        mWifiAdmin.OpenWifi();             
        refreshWifi();
    }
     
    private void refreshWifi() {
        mWifiAdmin.StartScan();
        list = mWifiAdmin.GetWifiList();
        if (list != null) {
            localWifi.clear();
            for(int i = 0; i < list.size(); i++) {
                mScanResult = list.get(i);
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("ssid", mScanResult.SSID);
                map.put("right_icon", R.drawable.wifi_icon);
                localWifi.add(map);
            }
            adapter = new SimpleAdapter(MainActivity.this, localWifi, R.layout.item_text_icon,
                    new String[]{"ssid","right_icon"}, new int[]{R.id.local_wifi_ssid,R.id.image_wifi});
            localList.setAdapter(adapter);
            localList.setOnItemClickListener(new MyOnListItemClickListener());
        }
    }
     
    private void onClickAction(String extraStr) {
        Intent intent = new Intent();
        intent.putExtra("wifiSsid", extraStr);
        intent.setClass(MainActivity.this, WifiMainActivity.class);
        MainActivity.this.startActivity(intent);
    }
     
    private class MyOnClickListener implements OnClickListener {
 
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch(v.getId()) {
            case R.id.wifiFresh:
                refreshWifi();
                break;
            default:
                break;
            }
             
        }      
    }
     
    private class MyOnListItemClickListener implements OnItemClickListener{
 
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            // TODO Auto-generated method stub
            Map<String, Object> map = (Map<String, Object>)MainActivity.this.localList.getItemAtPosition(position);
            String wifi_ssid = (String) map.get("ssid");
            if (wifi_ssid == null) {
                wifi_ssid = "";
            }
            onClickAction(wifi_ssid);
        }
         
    }
     
    public class WifiReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
                refreshWifi();
                Message msg = new Message();
                msg.what = MSG_ID_STOP_SCAN;
                wifiHandler.sendMessage(msg);
            }
        }      
    }
 
}

[4].[图片] 1.png 跳至 [1] [2] [3] [4] [5] [6] [7]

技术分享

[5].[图片] 2.png 跳至 [1] [2] [3] [4] [5] [6] [7]

技术分享

[6].[图片] 3.png 跳至 [1] [2] [3] [4] [5] [6] [7]

技术分享

[7].[图片] 4.png 跳至 [1] [2] [3] [4] [5] [6] [7]

技术分享

方便快捷管理wifi

标签:

原文地址:http://blog.csdn.net/u014311070/article/details/42805305

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!