内容简介:点击Wifi热点配置选项,会弹出一个对话框,内容都是从mWifiConfig获取的,这个mWifiConfig是在构造的时候赋值:继续跟代码
点击Wifi热点配置选项,会弹出一个对话框, WifiApDialog.java
。这个对话框会在onCreate的时候填入一些默认内容:
if (mWifiConfig != null) { mSsid.setText(mWifiConfig.SSID); if (mWifiConfig.apBand == 0) { mBandIndex = 0; } else { mBandIndex = 1; } mSecurity.setSelection(mSecurityTypeIndex); if (mSecurityTypeIndex == WPA2_INDEX) { mPassword.setText(mWifiConfig.preSharedKey); } }
内容都是从mWifiConfig获取的,这个mWifiConfig是在构造的时候赋值:
// TetherSettings.java private void initWifiTethering() { final Activity activity = getActivity(); mWifiConfig = mWifiManager.getWifiApConfiguration(); // 这里获取的 mSecurityType = getResources().getStringArray(R.array.wifi_ap_security); mCreateNetwork = findPreference(WIFI_AP_SSID_AND_SECURITY); mRestartWifiApAfterConfigChange = false; if (mWifiConfig == null) { final String s = activity.getString( com.android.internal.R.string.wifi_tether_configure_ssid_default); mCreateNetwork.setSummary(String.format(activity.getString(CONFIG_SUBTEXT), s, mSecurityType[WifiApDialog.OPEN_INDEX])); } else { int index = WifiApDialog.getSecurityTypeIndex(mWifiConfig); mCreateNetwork.setSummary(String.format(activity.getString(CONFIG_SUBTEXT), mWifiConfig.SSID, mSecurityType[index])); } } @Override public Dialog onCreateDialog(int id) { if (id == DIALOG_AP_SETTINGS) { final Activity activity = getActivity(); mDialog = new WifiApDialog(activity, this, mWifiConfig); return mDialog; } return null; }
继续跟代码
// WifiServiceImpl.java /** * see {@link WifiManager#getWifiApConfiguration()} * @return soft access point configuration */ public WifiConfiguration getWifiApConfiguration() { enforceAccessPermission(); return mWifiStateMachine.syncGetWifiApConfiguration(); }
// WifiStateMachine.java public WifiConfiguration syncGetWifiApConfiguration() { return mWifiApConfigStore.getApConfiguration(); }
// WifiApConfigStore.java /** * Generate a default WPA2 based configuration with a random password. * We are changing the Wifi Ap configuration storage from secure settings to a * flat file accessible only by the system. A WPA2 based default configuration * will keep the device secure after the update. */ private WifiConfiguration getDefaultApConfiguration() { WifiConfiguration config = new WifiConfiguration(); config.SSID = mContext.getResources().getString( R.string.wifi_tether_configure_ssid_default); config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK); String randomUUID = UUID.randomUUID().toString(); //first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx config.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9, 13); return config; }
所以,只需要在 getDefaultApConfiguration
配置默认的热点相关内容。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- springboot 默认日志配置
- SpringBoot 实战 (七) | 默认日志配置
- 「快学SpringBoot」配置文件的加载顺序和配置项默认值设置
- Struts2中配置默认Action
- RabbitMQ默认集群模式搭建配置实现步骤
- Docker-解决空间不足的问题以及修改默认配置
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。