我的编程空间,编程开发者的网络收藏夹
学习永远不晚

Android 连接Wifi和创建Wifi热点的实例

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

Android 连接Wifi和创建Wifi热点的实例

本文实例讲述了连接Wifi和创建Wifi热点的方法。分享给大家供大家参考,具体如下:

android的热点功能不可见,用了反射的技术搞定之外。 

Eclipse设置语言为utf-8才能查看中文注释

上代码:

MainActivity.java


package com.widget.hotspot; 
import android.os.Bundle; 
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.widget.Button; 
public class MainActivity extends Activity { 
  public static final String TAG = "MainActivity"; 
  private Button mBtn1, mBtn2; 
  private WifiAdmin mWifiAdmin; 
  private Context mContext = null; 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    mContext = this; 
    setContentView(R.layout.activity_main); 
    mBtn1 = (Button)findViewById(R.id.button1); 
    mBtn2 = (Button)findViewById(R.id.button2); 
    mBtn1.setText("点击连接Wifi"); 
    mBtn2.setText("点击创建Wifi热点"); 
    mBtn1.setOnClickListener(new Button.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
        // TODO Auto-generated method stub 
        mWifiAdmin = new WifiAdmin(mContext) { 
          @Override 
          public void myUnregisterReceiver(BroadcastReceiver receiver) { 
            // TODO Auto-generated method stub 
            MainActivity.this.unregisterReceiver(receiver); 
          } 
          @Override 
          public Intent myRegisterReceiver(BroadcastReceiver receiver, 
              IntentFilter filter) { 
            // TODO Auto-generated method stub 
            MainActivity.this.registerReceiver(receiver, filter); 
            return null; 
          } 
          @Override 
          public void onNotifyWifiConnected() { 
            // TODO Auto-generated method stub 
            Log.v(TAG, "have connected success!"); 
            Log.v(TAG, "###############################"); 
          } 
          @Override 
          public void onNotifyWifiConnectFailed() { 
            // TODO Auto-generated method stub 
            Log.v(TAG, "have connected failed!"); 
            Log.v(TAG, "###############################"); 
          } 
        }; 
        mWifiAdmin.openWifi(); 
        mWifiAdmin.addNetwork(mWifiAdmin.createWifiInfo("YOU_WIFI", "MM123456", WifiAdmin.TYPE_WPA)); 
      } 
    }); 
    mBtn2.setOnClickListener(new Button.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
        // TODO Auto-generated method stub 
        WifiApAdmin wifiAp = new WifiApAdmin(mContext); 
        wifiAp.startWifiAp("\"HotSpot\"", "hhhhhh123"); 
      } 
    }); 
  } 
  @Override 
  public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.activity_main, menu); 
    return true; 
  } 
   @Override 
    public void onResume() { 
      super.onResume(); 
      Log.d("Rssi", "Registered"); 
    } 
    @Override 
    public void onPause() { 
      super.onPause(); 
      Log.d("Rssi", "Unregistered"); 
    } 
} 

WifiAdmin.java


package com.widget.hotspot;  
import java.util.List; 
import java.util.Timer; 
import java.util.TimerTask; 
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.content.IntentFilter; 
import android.net.ConnectivityManager; 
import android.net.NetworkInfo; 
import android.net.NetworkInfo.DetailedState; 
import android.net.wifi.ScanResult; 
import android.net.wifi.WifiConfiguration; 
import android.net.wifi.WifiInfo; 
import android.net.wifi.WifiManager; 
import android.net.wifi.WifiManager.WifiLock; 
import android.util.Log; 
public abstract class WifiAdmin { 
  private static final String TAG = "WifiAdmin"; 
  private WifiManager mWifiManager; 
  private WifiInfo mWifiInfo; 
  // 扫描出的网络连接列表 
  private List<ScanResult> mWifiList; 
  private List<WifiConfiguration> mWifiConfiguration; 
  private WifiLock mWifiLock; 
  private String mPasswd = ""; 
  private String mSSID = ""; 
  private Context mContext = null; 
  public WifiAdmin(Context context) { 
    mContext = context; 
    // 取得WifiManager对象 
    mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); 
    // 取得WifiInfo对象 
    mWifiInfo = mWifiManager.getConnectionInfo(); 
    Log.v(TAG, "getIpAddress = " + mWifiInfo.getIpAddress()); 
  } 
  // 打开WIFI 
  public void openWifi() { 
    if (!mWifiManager.isWifiEnabled()) { 
      mWifiManager.setWifiEnabled(true); 
    } 
  } 
  // 关闭WIFI 
  public void closeWifi() { 
    if (mWifiManager.isWifiEnabled()) { 
      mWifiManager.setWifiEnabled(false); 
    } 
  } 
  public abstract Intent myRegisterReceiver(BroadcastReceiver receiver, IntentFilter filter); 
  public abstract void myUnregisterReceiver(BroadcastReceiver receiver); 
  public abstract void onNotifyWifiConnected(); 
  public abstract void onNotifyWifiConnectFailed(); 
  // 添加一个网络并连接 
  public void addNetwork(WifiConfiguration wcg) { 
    register(); 
    WifiApAdmin.closeWifiAp(mContext); 
    int wcgID = mWifiManager.addNetwork(wcg); 
    boolean b = mWifiManager.enableNetwork(wcgID, true); 
  } 
  public static final int TYPE_NO_PASSWD = 0x11; 
  public static final int TYPE_WEP = 0x12; 
  public static final int TYPE_WPA = 0x13; 
  public void addNetwork(String ssid, String passwd, int type) { 
    if (ssid == null || passwd == null || ssid.equals("")) { 
      Log.e(TAG, "addNetwork() ## nullpointer error!"); 
      return; 
    } 
    if (type != TYPE_NO_PASSWD && type != TYPE_WEP && type != TYPE_WPA) { 
      Log.e(TAG, "addNetwork() ## unknown type = " + type); 
    } 
    stopTimer(); 
    unRegister(); 
    addNetwork(createWifiInfo(ssid, passwd, type)); 
  } 
  private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
      // TODO Auto-generated method stub 
      if (intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)) { 
        Log.d(TAG, "RSSI changed"); 
        //有可能是正在获取,或者已经获取了 
        Log.d(TAG, " intent is " + WifiManager.RSSI_CHANGED_ACTION); 
        if (isWifiContected(mContext) == WIFI_CONNECTED) { 
          stopTimer(); 
          onNotifyWifiConnected(); 
          unRegister(); 
        } else if (isWifiContected(mContext) == WIFI_CONNECT_FAILED) { 
          stopTimer(); 
          closeWifi(); 
          onNotifyWifiConnectFailed(); 
          unRegister(); 
        } else if (isWifiContected(mContext) == WIFI_CONNECTING) { 
        } 
      } 
    } 
  }; 
  private final int STATE_REGISTRING = 0x01; 
  private final int STATE_REGISTERED = 0x02; 
  private final int STATE_UNREGISTERING = 0x03; 
  private final int STATE_UNREGISTERED = 0x04; 
  private int mHaveRegister = STATE_UNREGISTERED; 
  private synchronized void register() { 
    Log.v(TAG, "register() ##mHaveRegister = " + mHaveRegister); 
    if (mHaveRegister == STATE_REGISTRING  
        || mHaveRegister == STATE_REGISTERED) { 
      return ; 
    } 
    mHaveRegister = STATE_REGISTRING; 
    myRegisterReceiver(mBroadcastReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION)); 
    mHaveRegister = STATE_REGISTERED; 
    startTimer(); 
  } 
  private synchronized void unRegister() { 
    Log.v(TAG, "unRegister() ##mHaveRegister = " + mHaveRegister); 
    if (mHaveRegister == STATE_UNREGISTERED  
        || mHaveRegister == STATE_UNREGISTERING) { 
      return ; 
    } 
    mHaveRegister = STATE_UNREGISTERING; 
    myUnregisterReceiver(mBroadcastReceiver); 
    mHaveRegister = STATE_UNREGISTERED; 
  } 
  private Timer mTimer = null; 
  private void startTimer() { 
    if (mTimer != null) { 
      stopTimer(); 
    } 
    mTimer = new Timer(true); 
//   mTimer.schedule(mTimerTask, 0, 20 * 1000);// 20s 
    mTimer.schedule(mTimerTask, 30 * 1000); 
  } 
  private TimerTask mTimerTask = new TimerTask() { 
    @Override 
    public void run() { 
      // TODO Auto-generated method stub 
      Log.e(TAG, "timer out!"); 
      onNotifyWifiConnectFailed(); 
      unRegister(); 
    } 
  }; 
  private void stopTimer() { 
    if (mTimer != null) { 
      mTimer.cancel(); 
      mTimer = null; 
    } 
  } 
  @Override 
  protected void finalize() { 
    try { 
      super.finalize(); 
      unRegister(); 
    } catch (Throwable e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } 
  } 
  public WifiConfiguration createWifiInfo(String SSID, String password, int type) { 
    Log.v(TAG, "SSID = " + SSID + "## Password = " + password + "## Type = " + type); 
    WifiConfiguration config = new WifiConfiguration(); 
    config.allowedAuthAlgorithms.clear(); 
    config.allowedGroupCiphers.clear(); 
    config.allowedKeyManagement.clear(); 
    config.allowedPairwiseCiphers.clear(); 
    config.allowedProtocols.clear(); 
    config.SSID = "\"" + SSID + "\""; 
    WifiConfiguration tempConfig = this.IsExsits(SSID); 
    if (tempConfig != null) { 
      mWifiManager.removeNetwork(tempConfig.networkId); 
    } 
    // 分为三种情况:1没有密码2用wep加密3用wpa加密 
    if (type == TYPE_NO_PASSWD) {// WIFICIPHER_NOPASS 
      config.wepKeys[0] = ""; 
      config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); 
      config.wepTxKeyIndex = 0; 
    } else if (type == TYPE_WEP) { // WIFICIPHER_WEP  
      config.hiddenSSID = true; 
      config.wepKeys[0] = "\"" + password + "\""; 
      config.allowedAuthAlgorithms 
          .set(WifiConfiguration.AuthAlgorithm.SHARED); 
      config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); 
      config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); 
      config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); 
      config.allowedGroupCiphers 
          .set(WifiConfiguration.GroupCipher.WEP104); 
      config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); 
      config.wepTxKeyIndex = 0; 
    } else if (type == TYPE_WPA) {  // WIFICIPHER_WPA 
      config.preSharedKey = "\"" + password + "\""; 
      config.hiddenSSID = true; 
      config.allowedAuthAlgorithms 
          .set(WifiConfiguration.AuthAlgorithm.OPEN); 
      config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); 
      config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); 
      config.allowedPairwiseCiphers 
          .set(WifiConfiguration.PairwiseCipher.TKIP); 
      // config.allowedProtocols.set(WifiConfiguration.Protocol.WPA); 
      config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); 
      config.allowedPairwiseCiphers 
          .set(WifiConfiguration.PairwiseCipher.CCMP); 
      config.status = WifiConfiguration.Status.ENABLED; 
    }  
    return config; 
  } 
  public static final int WIFI_CONNECTED = 0x01; 
  public static final int WIFI_CONNECT_FAILED = 0x02; 
  public static final int WIFI_CONNECTING = 0x03; 
   
  public int isWifiContected(Context context) { 
    ConnectivityManager connectivityManager = (ConnectivityManager) context 
        .getSystemService(Context.CONNECTIVITY_SERVICE); 
    NetworkInfo wifiNetworkInfo = connectivityManager 
        .getNetworkInfo(ConnectivityManager.TYPE_WIFI); 
    Log.v(TAG, "isConnectedOrConnecting = " + wifiNetworkInfo.isConnectedOrConnecting()); 
    Log.d(TAG, "wifiNetworkInfo.getDetailedState() = " + wifiNetworkInfo.getDetailedState()); 
    if (wifiNetworkInfo.getDetailedState() == DetailedState.OBTAINING_IPADDR 
        || wifiNetworkInfo.getDetailedState() == DetailedState.CONNECTING) { 
      return WIFI_CONNECTING; 
    } else if (wifiNetworkInfo.getDetailedState() == DetailedState.CONNECTED) { 
      return WIFI_CONNECTED; 
    } else { 
      Log.d(TAG, "getDetailedState() == " + wifiNetworkInfo.getDetailedState()); 
      return WIFI_CONNECT_FAILED; 
    } 
  } 
  private WifiConfiguration IsExsits(String SSID) { 
    List<WifiConfiguration> existingConfigs = mWifiManager.getConfiguredNetworks(); 
    for (WifiConfiguration existingConfig : existingConfigs) { 
      if (existingConfig.SSID.equals("\"" + SSID + "\"") ) { 
        return existingConfig; 
      } 
    } 
    return null; 
  } 
  // 断开指定ID的网络 
  public void disconnectWifi(int netId) { 
    mWifiManager.disableNetwork(netId); 
    mWifiManager.disconnect(); 
  } 
  // 检查当前WIFI状态 
  public int checkState() { 
    return mWifiManager.getWifiState(); 
  } 
  // 锁定WifiLock 
  public void acquireWifiLock() { 
    mWifiLock.acquire(); 
  } 
  // 解锁WifiLock 
  public void releaseWifiLock() { 
    // 判断时候锁定 
    if (mWifiLock.isHeld()) { 
      mWifiLock.acquire(); 
    } 
  } 
  // 创建一个WifiLock 
  public void creatWifiLock() { 
    mWifiLock = mWifiManager.createWifiLock("Test"); 
  } 
  // 得到配置好的网络 
  public List<WifiConfiguration> getConfiguration() { 
    return mWifiConfiguration; 
  } 
  // 指定配置好的网络进行连接 
  public void connectConfiguration(int index) { 
    // 索引大于配置好的网络索引返回 
    if (index > mWifiConfiguration.size()) { 
      return; 
    } 
    // 连接配置好的指定ID的网络 
    mWifiManager.enableNetwork(mWifiConfiguration.get(index).networkId, 
        true); 
  } 
  public void startScan() { 
    mWifiManager.startScan(); 
    mWifiList = mWifiManager.getScanResults(); 
    mWifiConfiguration = mWifiManager.getConfiguredNetworks(); 
  } 
  // 得到网络列表 
  public List<ScanResult> getWifiList() { 
    return mWifiList; 
  } 
  // 查看扫描结果 
  public StringBuilder lookUpScan() { 
    StringBuilder stringBuilder = new StringBuilder(); 
    for (int i = 0; i < mWifiList.size(); i++) { 
      stringBuilder 
          .append("Index_" + new Integer(i + 1).toString() + ":"); 
      // 将ScanResult信息转换成一个字符串包 
      // 其中把包括:BSSID、SSID、capabilities、frequency、level 
      stringBuilder.append((mWifiList.get(i)).toString()); 
      stringBuilder.append("/n"); 
    } 
    return stringBuilder; 
  } 
  // 得到MAC地址 
  public String getMacAddress() { 
    return (mWifiInfo == null) ? "NULL" : mWifiInfo.getMacAddress(); 
  } 
  // 得到接入点的BSSID 
  public String getBSSID() { 
    return (mWifiInfo == null) ? "NULL" : mWifiInfo.getBSSID(); 
  } 
  // 得到IP地址 
  public int getIPAddress() { 
    return (mWifiInfo == null) ? 0 : mWifiInfo.getIpAddress(); 
  } 
  // 得到连接的ID 
  public int getNetworkId() { 
    return (mWifiInfo == null) ? 0 : mWifiInfo.getNetworkId(); 
  } 
  // 得到WifiInfo的所有信息包 
  public String getWifiInfo() { 
    return (mWifiInfo == null) ? "NULL" : mWifiInfo.toString(); 
  } 
} 

WifiApAdmin.java


package com.widget.hotspot; 
import java.lang.reflect.InvocationTargetException; 
import java.lang.reflect.Method; 
import java.util.Timer; 
import java.util.TimerTask; 
import android.content.Context; 
import android.net.wifi.WifiConfiguration; 
import android.net.wifi.WifiManager; 
import android.util.Log; 
 
public class WifiApAdmin { 
  public static final String TAG = "WifiApAdmin"; 
  public static void closeWifiAp(Context context) { 
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);  
    closeWifiAp(wifiManager); 
  } 
  private WifiManager mWifiManager = null; 
  private Context mContext = null; 
  public WifiApAdmin(Context context) { 
    mContext = context; 
    mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);  
    closeWifiAp(mWifiManager); 
  } 
  private String mSSID = ""; 
  private String mPasswd = ""; 
  public void startWifiAp(String ssid, String passwd) { 
    mSSID = ssid; 
    mPasswd = passwd; 
    if (mWifiManager.isWifiEnabled()) { 
      mWifiManager.setWifiEnabled(false); 
    }  
    stratWifiAp(); 
    MyTimerCheck timerCheck = new MyTimerCheck() { 
      @Override 
      public void doTimerCheckWork() { 
        // TODO Auto-generated method stub 
        if (isWifiApEnabled(mWifiManager)) { 
          Log.v(TAG, "Wifi enabled success!"); 
          this.exit(); 
        } else { 
          Log.v(TAG, "Wifi enabled failed!"); 
        } 
      } 
      @Override 
      public void doTimeOutWork() { 
        // TODO Auto-generated method stub 
        this.exit(); 
      } 
    }; 
    timerCheck.start(15, 1000); 
  } 
  public void stratWifiAp() { 
    Method method1 = null; 
    try { 
      method1 = mWifiManager.getClass().getMethod("setWifiApEnabled", 
          WifiConfiguration.class, boolean.class); 
      WifiConfiguration netConfig = new WifiConfiguration(); 
      netConfig.SSID = mSSID; 
      netConfig.preSharedKey = mPasswd; 
      netConfig.allowedAuthAlgorithms 
          .set(WifiConfiguration.AuthAlgorithm.OPEN); 
      netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); 
      netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); 
      netConfig.allowedKeyManagement 
          .set(WifiConfiguration.KeyMgmt.WPA_PSK); 
      netConfig.allowedPairwiseCiphers 
          .set(WifiConfiguration.PairwiseCipher.CCMP); 
      netConfig.allowedPairwiseCiphers 
          .set(WifiConfiguration.PairwiseCipher.TKIP); 
      netConfig.allowedGroupCiphers 
          .set(WifiConfiguration.GroupCipher.CCMP); 
      netConfig.allowedGroupCiphers 
          .set(WifiConfiguration.GroupCipher.TKIP); 
      method1.invoke(mWifiManager, netConfig, true); 
    } catch (IllegalArgumentException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } catch (IllegalAccessException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } catch (InvocationTargetException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } catch (SecurityException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } catch (NoSuchMethodException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } 
  } 
  private static void closeWifiAp(WifiManager wifiManager) { 
    if (isWifiApEnabled(wifiManager)) { 
      try { 
        Method method = wifiManager.getClass().getMethod("getWifiApConfiguration"); 
        method.setAccessible(true); 
        WifiConfiguration config = (WifiConfiguration) method.invoke(wifiManager); 
        Method method2 = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class); 
        method2.invoke(wifiManager, config, false); 
      } catch (NoSuchMethodException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
      } catch (IllegalArgumentException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
      } catch (IllegalAccessException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
      } catch (InvocationTargetException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
      } 
    } 
  } 
  private static boolean isWifiApEnabled(WifiManager wifiManager) { 
    try { 
      Method method = wifiManager.getClass().getMethod("isWifiApEnabled"); 
      method.setAccessible(true); 
      return (Boolean) method.invoke(wifiManager); 
    } catch (NoSuchMethodException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } catch (Exception e) { 
      e.printStackTrace(); 
    } 
    return false; 
  } 
} 

MyTimeCheck.java


package com.widget.hotspot; 
public abstract class MyTimerCheck { 
  private int mCount = 0; 
  private int mTimeOutCount = 1; 
  private int mSleepTime = 1000; // 1s 
  private boolean mExitFlag = false; 
  private Thread mThread = null; 
   
  public abstract void doTimerCheckWork(); 
  public abstract void doTimeOutWork(); 
  public MyTimerCheck() { 
    mThread = new Thread(new Runnable() { 
      @Override 
      public void run() { 
        // TODO Auto-generated method stub 
        while (!mExitFlag) { 
          mCount++; 
          if (mCount < mTimeOutCount) { 
            doTimerCheckWork(); 
            try { 
              mThread.sleep(mSleepTime); 
            } catch (InterruptedException e) { 
              // TODO Auto-generated catch block 
              e.printStackTrace(); 
              exit(); 
            } 
          } else { 
            doTimeOutWork(); 
          } 
        } 
      } 
    }); 
  } 
   
  public void start(int timeOutCount, int sleepTime) { 
    mTimeOutCount = timeOutCount; 
    mSleepTime = sleepTime; 
    mThread.start(); 
  } 
  public void exit() { 
    mExitFlag = true; 
  } 
} 
您可能感兴趣的文章:Android获取当前已连接的wifi信号强度的方法android编程实现设置、打开wifi热点共享供他人连接的方法Android连接指定Wifi的方法实例代码android连接wifi时获取广播地址代码Android编程实现获取当前连接wifi名字的方法ubuntu用wifi连接android调试程序的步骤Android 判断是否连接成功了指定wifiAndroid编程判断是否连接网络的方法【WiFi及3G判断】通过WIFI(不用数据线)连接Android手机调试Android通过wifi连接手机(不需要root)Android编程实现wifi扫描及连接的方法


免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

Android 连接Wifi和创建Wifi热点的实例

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

Android 连接Wifi和创建Wifi热点的实例

本文实例讲述了连接Wifi和创建Wifi热点的方法。分享给大家供大家参考,具体如下:android的热点功能不可见,用了反射的技术搞定之外。 Eclipse设置语言为utf-8才能查看中文注释 上代码:MainActivity.javap
2022-06-06

Android连接指定Wifi的方法实例代码

本篇文章主要记录一下Android中打开Wifi、获取Wifi接入点信息及连接指接入点的方法。 自己写的demo主要用于测试接口的基本功能,因此界面及底层逻辑比较粗糙。 demo的整体界面如下所示:上图中的OPEN按键负责开启Wifi; G
2022-06-06

如何解决win7无法创建wifi热点的问题

这篇文章给大家分享的是有关如何解决win7无法创建wifi热点的问题的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。一、按“win+r”唤出运行,在运行内输入“servoces.msc”。二、在弹出的服务窗口中,按
2023-06-28

android编程实现设置、打开wifi热点共享供他人连接的方法

本文实例讲述了android编程实现设置、打开wifi热点共享供他人连接的方法。分享给大家供大家参考,具体如下: 用过快牙的朋友应该知道它们在两天设备之间传输文件的时候使用的是wifi热点,然后另一台便连接这个热点再进行传输。快牙传输速度惊
2022-06-06

Win10怎么创建Wifi热点?Win10系统笔记本设置WiFi共享的方法详解

如今,Win10创建Wifi热点非常简单,可以使用的工具非常多,只需要在Win10笔记本中安装使用W编程客栈ifi共享精灵、360安全卫士、金山卫士、鲁大师、116Wifi等软件,就可以轻松的在笔记本创建Wifi热点,让附近的智能手机/平板
2023-06-08

Android编程实现获取当前连接wifi名字的方法

本文实例讲述了Android编程实现获取当前连接wifi名字的方法。分享给大家供大家参考,具体如下:WifiManager wifiMgr = (WifiManager) mActivity.getSystemService(Context
2022-06-06

如何解决XP系统下160WIFI创建WiFi热点后手机无法正常上网的问题

这篇文章将为大家详细讲解有关如何解决XP系统下160WIFI创建WiFi热点后手机无法正常上网的问题,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。  160WiFi是一款免费的无线路由软件,
2023-06-14

编程热搜

  • Android:VolumeShaper
    VolumeShaper(支持版本改一下,minsdkversion:26,android8.0(api26)进一步学习对声音的编辑,可以让音频的声音有变化的播放 VolumeShaper.Configuration的三个参数 durati
    Android:VolumeShaper
  • Android崩溃异常捕获方法
    开发中最让人头疼的是应用突然爆炸,然后跳回到桌面。而且我们常常不知道这种状况会何时出现,在应用调试阶段还好,还可以通过调试工具的日志查看错误出现在哪里。但平时使用的时候给你闹崩溃,那你就欲哭无泪了。 那么今天主要讲一下如何去捕捉系统出现的U
    Android崩溃异常捕获方法
  • android开发教程之获取power_profile.xml文件的方法(android运行时能耗值)
    系统的设置–>电池–>使用情况中,统计的能耗的使用情况也是以power_profile.xml的value作为基础参数的1、我的手机中power_profile.xml的内容: HTC t328w代码如下:
    android开发教程之获取power_profile.xml文件的方法(android运行时能耗值)
  • Android SQLite数据库基本操作方法
    程序的最主要的功能在于对数据进行操作,通过对数据进行操作来实现某个功能。而数据库就是很重要的一个方面的,Android中内置了小巧轻便,功能却很强的一个数据库–SQLite数据库。那么就来看一下在Android程序中怎么去操作SQLite数
    Android SQLite数据库基本操作方法
  • ubuntu21.04怎么创建桌面快捷图标?ubuntu软件放到桌面的技巧
    工作的时候为了方便直接打开编辑文件,一些常用的软件或者文件我们会放在桌面,但是在ubuntu20.04下直接直接拖拽文件到桌面根本没有效果,在进入桌面后发现软件列表中的软件只能收藏到面板,无法复制到桌面使用,不知道为什么会这样,似乎并不是很
    ubuntu21.04怎么创建桌面快捷图标?ubuntu软件放到桌面的技巧
  • android获取当前手机号示例程序
    代码如下: public String getLocalNumber() { TelephonyManager tManager =
    android获取当前手机号示例程序
  • Android音视频开发(三)TextureView
    简介 TextureView与SurfaceView类似,可用于显示视频或OpenGL场景。 与SurfaceView的区别 SurfaceView不能使用变换和缩放等操作,不能叠加(Overlay)两个SurfaceView。 Textu
    Android音视频开发(三)TextureView
  • android获取屏幕高度和宽度的实现方法
    本文实例讲述了android获取屏幕高度和宽度的实现方法。分享给大家供大家参考。具体分析如下: 我们需要获取Android手机或Pad的屏幕的物理尺寸,以便于界面的设计或是其他功能的实现。下面就介绍讲一讲如何获取屏幕的物理尺寸 下面的代码即
    android获取屏幕高度和宽度的实现方法
  • Android自定义popupwindow实例代码
    先来看看效果图:一、布局
  • Android第一次实验
    一、实验原理 1.1实验目标 编程实现用户名与密码的存储与调用。 1.2实验要求 设计用户登录界面、登录成功界面、用户注册界面,用户注册时,将其用户名、密码保存到SharedPreference中,登录时输入用户名、密码,读取SharedP
    Android第一次实验

目录