三星s5最新报价 连接热点显示 androidAP7620是什么意思

下次自动登录
现在的位置:
& 综合 & 正文
android AP 热点介绍 和接口使用
以下基于android ics系统
Android AP接口属性为 @hide,不对外开放,但通过revoke机制调用到。
Ap的几个重要接口
getWifiApState
setWifiApEnabled
getWifiApConfiguration
isWifiApEnabled
使用方法:
package com.lenovo.channel.method.ap.
import java.lang.reflect.F
import java.lang.reflect.M
import java.util.HashM
import java.util.M
import android.net.wifi.WifiC
import android.net.wifi.WifiM
import android.os.B
import com.lenovo.channel.method.ap.hotspot.Hotspot.WifiApS
import mon.BeanU
import mon.L
class WifiApManager {
private static final String tag = "WifiApManager";
private static final String METHOD_GET_WIFI_AP_STATE = "getWifiApState";
private static final String METHOD_SET_WIFI_AP_ENABLED = "setWifiApEnabled";
private static final String METHOD_GET_WIFI_AP_CONFIG = "getWifiApConfiguration";
private static final String METHOD_IS_WIFI_AP_ENABLED = "isWifiApEnabled";
private static final Map&String, Method& methodMap = new HashMap&String, Method&();
private static Boolean mIsS
private static boolean mIsH
public synchronized static final boolean isSupport() {
if (mIsSupport != null) {
return mIsS
boolean result = Build.VERSION.SDK_INT & Build.VERSION_CODES.FROYO;
if (result) {
Field field = WifiConfiguration.class.getDeclaredField("mWifiApProfile");
mIsHtc = field != null;
} catch (Exception e) {
if (result) {
String name = METHOD_GET_WIFI_AP_STATE;
Method method = WifiManager.class.getMethod(name);
methodMap.put(name, method);
result = method != null;
} catch (SecurityException e) {
Logger.e(tag, "SecurityException", e);
} catch (NoSuchMethodException e) {
Logger.e(tag, "NoSuchMethodException", e);
if (result) {
String name = METHOD_SET_WIFI_AP_ENABLED;
Method method = WifiManager.class.getMethod(name, WifiConfiguration.class, boolean.class);
methodMap.put(name, method);
result = method != null;
} catch (SecurityException e) {
Logger.e(tag, "SecurityException", e);
} catch (NoSuchMethodException e) {
Logger.e(tag, "NoSuchMethodException", e);
if (result) {
String name = METHOD_GET_WIFI_AP_CONFIG;
Method method = WifiManager.class.getMethod(name);
methodMap.put(name, method);
result = method != null;
} catch (SecurityException e) {
Logger.e(tag, "SecurityException", e);
} catch (NoSuchMethodException e) {
Logger.e(tag, "NoSuchMethodException", e);
if (result) {
String name = getSetWifiApConfigName();
Method method = WifiManager.class.getMethod(name, WifiConfiguration.class);
methodMap.put(name, method);
result = method != null;
} catch (SecurityException e) {
Logger.e(tag, "SecurityException", e);
} catch (NoSuchMethodException e) {
Logger.e(tag, "NoSuchMethodException", e);
if (result) {
String name = METHOD_IS_WIFI_AP_ENABLED;
Method method = WifiManager.class.getMethod(name);
methodMap.put(name, method);
result = method != null;
} catch (SecurityException e) {
Logger.e(tag, "SecurityException", e);
} catch (NoSuchMethodException e) {
Logger.e(tag, "NoSuchMethodException", e);
mIsSupport =
return isSupport();
private final WifiManager mWifiM
WifiApManager(WifiManager manager) {
if (!isSupport()) {
throw new RuntimeException("Unsupport Ap!");
Logger.i(tag, "Build.BRAND -----------& " + Build.BRAND);
mWifiManager =
public WifiManager getWifiManager() {
return mWifiM
public int getWifiApState() {
Method method = methodMap.get(METHOD_GET_WIFI_AP_STATE);
return (Integer) method.invoke(mWifiManager);
} catch (Exception e) {
Logger.e(tag, e.getMessage(), e);
return WifiApState.WIFI_AP_STATE_UNKWON;
private WifiConfiguration getHtcWifiApConfiguration(WifiConfiguration standard){
WifiConfiguration htcWifiConfig =
Object mWifiApProfileValue = BeanUtils.getFieldValue(standard, "mWifiApProfile");
if (mWifiApProfileValue != null) {
htcWifiConfig.SSID = (String)BeanUtils.getFieldValue(mWifiApProfileValue, "SSID");
} catch (Exception e) {
Logger.e(tag, "" + e.getMessage(), e);
return htcWifiC
public WifiConfiguration getWifiApConfiguration() {
WifiConfiguration configuration = null;
Method method = methodMap.get(METHOD_GET_WIFI_AP_CONFIG);
configuration = (WifiConfiguration) method.invoke(mWifiManager);
if(isHtc()){
configuration = getHtcWifiApConfiguration(configuration);
} catch (Exception e) {
Logger.e(tag, e.getMessage(), e);
public boolean setWifiApConfiguration(WifiConfiguration netConfig) {
boolean result = false;
if (isHtc()) {
setupHtcWifiConfiguration(netConfig);
Method method = methodMap.get(getSetWifiApConfigName());
Class&?&[] params = method.getParameterTypes();
for (Class&?& clazz : params) {
Logger.i(tag, "param -& " + clazz.getSimpleName());
if (isHtc()) {
int rValue = (Integer) method.invoke(mWifiManager, netConfig);
Logger.i(tag, "rValue -& " + rValue);
result = rValue & 0;
result = (Boolean) method.invoke(mWifiManager, netConfig);
} catch (Exception e) {
Logger.e(tag, "", e);
public boolean setWifiApEnabled(WifiConfiguration configuration, boolean enabled) {
boolean result = false;
Method method = methodMap.get(METHOD_SET_WIFI_AP_ENABLED);
result = (Boolean)method.invoke(mWifiManager, configuration, enabled);
} catch (Exception e) {
Logger.e(tag, e.getMessage(), e);
public boolean isWifiApEnabled() {
boolean result = false;
Method method = methodMap.get(METHOD_IS_WIFI_AP_ENABLED);
result = (Boolean)method.invoke(mWifiManager);
} catch (Exception e) {
Logger.e(tag, e.getMessage(), e);
private void setupHtcWifiConfiguration(WifiConfiguration config) {
Logger.d(tag, "config=
" + config);
Object mWifiApProfileValue = BeanUtils.getFieldValue(config, "mWifiApProfile");
if (mWifiApProfileValue != null) {
BeanUtils.setFieldValue(mWifiApProfileValue, "SSID", config.SSID);
BeanUtils.setFieldValue(mWifiApProfileValue, "BSSID", config.BSSID);
BeanUtils.setFieldValue(mWifiApProfileValue, "secureType", "open");
BeanUtils.setFieldValue(mWifiApProfileValue, "dhcpEnable", 1);
} catch (Exception e) {
Logger.e(tag, "" + e.getMessage(), e);
public static boolean isHtc() {
return mIsH
private static String getSetWifiApConfigName() {
return mIsHtc? "setWifiApConfig": "setWifiApConfiguration";
下面是一个英文页面发现的文档,集合了很多wifi连接的技术方案:
Android Wifi Hotspot Manager Class
08 2012 May
Android has the great option to let you Tether your connection via wifi, but as developer you got little to none control over this mechanism.
Therefore i wrote a class to correct this: WifiApManager.
With this class you can enable the check the current Status of the Hotspot, enable/disable it, get/set the current AP configuration and also get the list of currently connected clients.
I also made an example to demonstrate it’s capabilities:
Download example Sourcecode + binaries
And here the source-code of the class WifiApManager.java:
package com.whitebyte.
import java.io.BufferedR
import java.io.FileR
import java.io.IOE
import java.lang.reflect.M
import java.net.InetA
import java.util.ArrayL
import android.content.C
import android.net.wifi.WifiC
import android.net.wifi.WifiM
import android.util.L
public class WifiApManager {private final WifiManager mWifiM
public WifiApManager(Context context) {mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);}
* Start AccessPoint mode with the specified
* configuration. If the radio is already running in
* AP mode, update the new configuration
* Note that starting in access point mode disables station
* mode operation
* @param wifiConfig SSID, security and channel details as part of WifiConfiguration
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/public boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) {try {if (enabled) { // disable WiFi in any casemWifiManager.setWifiEnabled(false);}
Method method = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);return (Boolean) method.invoke(mWifiManager, wifiConfig, enabled);} catch (Exception e) {Log.e(this.getClass().toString(), "", e);}}
* Gets the Wi-Fi enabled state.
* @return {@link WIFI_AP_STATE}
* @see #isWifiApEnabled()
*/public WIFI_AP_STATE getWifiApState() {try {Method method = mWifiManager.getClass().getMethod("getWifiApState");
int tmp = ((Integer)method.invoke(mWifiManager));
// Fix for Android 4if (tmp & 10) {tmp = tmp - 10;}
return WIFI_AP_STATE.class.getEnumConstants()[tmp];} catch (Exception e) {Log.e(this.getClass().toString(), "", e);return WIFI_AP_STATE.WIFI_AP_STATE_FAILED;}}
* Return whether Wi-Fi AP is enabled or disabled.
* @return {@code true} if Wi-Fi AP is enabled
* @see #getWifiApState()
* @hide Dont open yet
public boolean isWifiApEnabled() {
return getWifiApState() == WIFI_AP_STATE.WIFI_AP_STATE_ENABLED;
* Gets the Wi-Fi AP Configuration.
* @return AP details in {@link WifiConfiguration}
public WifiConfiguration getWifiApConfiguration() {try {Method method = mWifiManager.getClass().getMethod("getWifiApConfiguration");return (WifiConfiguration) method.invoke(mWifiManager);} catch (Exception e) {Log.e(this.getClass().toString(), "", e);}
* Sets the Wi-Fi AP Configuration.
* @return {@code true} if the operation succeeded, {@code false} otherwise
public boolean setWifiApConfiguration(WifiConfiguration wifiConfig) {
try {Method method = mWifiManager.getClass().getMethod("setWifiApConfiguration", WifiConfiguration.class);return (Boolean) method.invoke(mWifiManager, wifiConfig);} catch (Exception e) {Log.e(this.getClass().toString(), "", e);}}
* Gets a list of the clients connected to the Hotspot, reachable timeout is 300
* @param onlyReachables {@code false} if the list should contain unreachable (probably disconnected) clients, {@code true} otherwise
* @return ArrayList of {@link ClientScanResult}
public ArrayList&ClientScanResult& getClientList(boolean onlyReachables) {
return getClientList(onlyReachables, 300);
* Gets a list of the clients connected to the Hotspot
* @param onlyReachables {@code false} if the list should contain unreachable (probably disconnected) clients, {@code true} otherwise
* @param reachableTimeout Reachable Timout in miliseconds
* @return ArrayList of {@link ClientScanResult}
*/public ArrayList&ClientScanResult& getClientList(boolean onlyReachables, int reachableTimeout) {BufferedReader br =ArrayList&ClientScanResult& result =
try {result = new ArrayList&ClientScanResult&();br = new BufferedReader(new FileReader("/proc/net/arp"));Swhile ((line = br.readLine()) != null) {String[] splitted = line.split(" +");
if ((splitted != null) && (splitted.length &= 4)) {// Basic sanity checkString mac = splitted[3];
if (mac.matches("..:..:..:..:..:..")) {boolean isReachable = InetAddress.getByName(splitted[0]).isReachable(reachableTimeout);
if (!onlyReachables || isReachable) {result.add(new ClientScanResult(splitted[0], splitted[3], splitted[5], isReachable));}}}}} catch (Exception e) {Log.e(this.getClass().toString(), e.getMessage());} finally {try {br.close();} catch (IOException e) {Log.e(this.getClass().toString(), e.getMessage());}}
&&&&推荐文章:
【上篇】【下篇】android编程实现设置、打开wifi热点共享供他人连接的方法
作者:luoboo525
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了android编程实现设置、打开wifi热点共享供他人连接的方法,涉及Android创建WiFi及设置共享的相关实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了android编程实现设置、打开wifi热点共享供他人连接的方法。分享给大家供大家参考,具体如下:
用过快牙的朋友应该知道它们在两天设备之间传输文件的时候使用的是wifi热点,然后另一台便连接这个热点再进行传输。快牙传输速度惊人应该跟它的这种机制有关系吧。不知道它的搜索机制是怎样的,但我想应该可以通过热点的名字来进行判断吧。下面我们就来探讨一下如何自动创建一个wifi热点吧
创建wifi热点首先需要手机支持,建议开发的哥们整个好点的手机,我们公司那些个山寨设备,几近有一半是不支持热点的;其实创建热点很简单,先获取到wifi的服务,再配置热点名称、密码等等,然后再通过反射打开它就OK了。
下面我们看看创建热点的代码实现:
package com.tel.lajoin.wifi.
import java.lang.reflect.M
import android.app.A
import android.content.C
import android.net.wifi.WifiC
import android.net.wifi.WifiM
import android.os.B
import android.view.V
import android.widget.B
public class HotspotActivity extends Activity {
private WifiManager wifiM
private boolean flag=
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获取wifi管理服务
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
open=(Button)findViewById(R.id.open_hotspot);
//通过按钮事件设置热点
open.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//如果是打开状态就关闭,如果是关闭就打开
setWifiApEnabled(flag);
// wifi热点开关
public boolean setWifiApEnabled(boolean enabled) {
if (enabled) { // disable WiFi in any case
//wifi和热点不能同时打开,所以打开热点的时候需要关闭wifi
wifiManager.setWifiEnabled(false);
//热点的配置类
WifiConfiguration apConfig = new WifiConfiguration();
//配置热点的名称(可以在名字后面加点随机数什么的)
apConfig.SSID = "YRCCONNECTION";
//配置热点的密码
apConfig.preSharedKey="";
//通过反射调用设置热点
Method method = wifiManager.getClass().getMethod(
"setWifiApEnabled", WifiConfiguration.class, Boolean.TYPE);
//返回热点打开状态
return (Boolean) method.invoke(wifiManager, apConfig, enabled);
} catch (Exception e) {
布局就不写了吧,就一按钮,人人都知道的东西,写了也没啥意思。要实现文件传输,当然我们还需要写一个连接热点的客户端吧。连接热点的流程首先是搜索热点然后再判断热点是否符合规则然后再进行连接。
package com.tel.lajoin.
import java.util.ArrayL
import java.util.L
import android.app.A
import android.content.BroadcastR
import android.content.C
import android.content.I
import android.content.IntentF
import android.net.wifi.ScanR
import android.net.wifi.WifiC
import android.net.wifi.WifiM
import android.os.B
public class MainActivity extends Activity {
private List&ScanResult& wifiL
private WifiManager wifiM
private List&String& passableHotsP
private WifiReceiver wifiR
private boolean isConnected=
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* 初始化参数 */
public void init() {
setContentView(R.layout.main);
connect=(Button)findViewById(R.id.connect);
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiReceiver = new WifiReceiver();
//通过按钮事件搜索热点
connect.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
wifiManager.startScan();
/* 监听热点变化 */
private final class WifiReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
wifiList = wifiManager.getScanResults();
if (wifiList == null || wifiList.size() == 0 || isConnected)
onReceiveNewNetworks(wifiList);
/*当搜索到新的wifi热点时判断该热点是否符合规格*/
public void onReceiveNewNetworks(List&ScanResult& wifiList){
passableHotsPot=new ArrayList&String&();
for(ScanResult result:wifiList){
System.out.println(result.SSID);
if((result.SSID).contains("YRCCONNECTION"))
passableHotsPot.add(result.SSID);
synchronized (this) {
connectToHotpot();
/*连接到热点*/
public void connectToHotpot(){
if(passableHotsPot==null || passableHotsPot.size()==0)
WifiConfiguration wifiConfig=this.setWifiParams(passableHotsPot.get(0));
int wcgID = wifiManager.addNetwork(wifiConfig);
boolean flag=wifiManager.enableNetwork(wcgID, true);
isConnected=
System.out.println("connect success? "+flag);
/*设置要连接的热点的参数*/
public WifiConfiguration setWifiParams(String ssid){
WifiConfiguration apConfig=new WifiConfiguration();
apConfig.SSID="\""+ssid+"\"";
apConfig.preSharedKey="\"\"";
apConfig.hiddenSSID =
apConfig.status = WifiConfiguration.Status.ENABLED;
apConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
apConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
apConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
apConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
apConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
apConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
return apC
protected void onDestroy() {
super.onDestroy();
/*销毁时注销广播*/
unregisterReceiver(wifiReceiver);
代码很简单,而且都有注释的,相信大伙儿能够看明白。 那就这样吧,至于文件传输建议还是去看看socket相关的文章吧。
希望本文所述对大家Android程序设计有所帮助。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具Android WIFI(7)
1.test.java文件
WifiManager mWifiManager =&(WifiManager) getSystemService(WIFI_SERVICE);
WifiConfiguration mWifiConfig &=&mWifiManager.getWifiApConfiguration();
WifiInfo wifiInfo &=&mWifiManager.getConnectionInfo();&
Log.i(TAG, &AP SSID :& + mWifiConfig.SSID + &AP password : & + mWifiConfig.preSharedKey);
& &uses-permission android:name=&android.permission.INTERNET&/& &&
& &uses-permission android:name=&android.permission.ACCESS_NETWORK_STATE&/&
& &uses-permission android:name=&android.permission.CHANGE_NETWORK_STATE& /&
& &uses-permission android:name=&android.permission.ACCESS_WIFI_STATE&/& &
& &uses-permission android:name=&android.permission.CHANGE_WIFI_STATE& /&
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:310365次
积分:6614
积分:6614
排名:第3576名
原创:213篇
转载:1076篇
评论:38条
(16)(20)(71)(67)(85)(69)(48)(48)(40)(139)(116)(54)(38)(121)(30)(54)(35)(77)(19)(100)(43)}

我要回帖

更多关于 s5 android 6.0 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信