Skip to content

Commit

Permalink
update to 1.0.5 Migrate to androidx
Browse files Browse the repository at this point in the history
  • Loading branch information
Reathin committed Aug 20, 2020
1 parent 5775adf commit 69f0ceb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#### 集成
```
implementation 'com.rairmmd:andesptouch:1.0.4'
implementation 'com.rairmmd:andesptouch:1.0.5'
```
#### 需要的权限
需要一下权限,库文件中已添加好了。
Expand All @@ -15,19 +15,22 @@ implementation 'com.rairmmd:andesptouch:1.0.4'
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
```
** ⚠️请注意适配高版本安卓,获取WiFi信息需要动态请求定位权限
** ⚠️请注意适配高版本安卓,获取WiFi信息需要动态请求定位权限

#### AndEsptouch
```
```java
AndEsptouch andEsptouch = new AndEsptouch.Builder(this)
.setSsid(ssid)//WiFi名字 可通过AndEsptouchHelper获得
.setBssid(bssid)//路由器mac地址 可通过AndEsptouchHelper获得
.setSSID(ssid)//WiFi名字 可通过AndEsptouchHelper获得
.setBSSID(bssid)//路由器mac地址 可通过AndEsptouchHelper获得
.setPassWord(password)//WiFi密码
.build();
andEsptouch.startEsptouchConfig();
andEsptouch.startConfig();

//停止配置
andEsptouch.stopConfig();
```
设置回调监听
```
```java
andEsptouch.setOnEsptouchTaskListener(new AndEsptouch.OnEsptouchTaskListener() {
@Override
public void onEsptouchTaskCallback(int code, String message) {
Expand Down Expand Up @@ -56,11 +59,13 @@ andEsptouch.setOnEsptouchTaskListener(new AndEsptouch.OnEsptouchTaskListener() {
#### AndEsptouchHelper
WiFi操作工具类
```
```java
//获取当前WiFi
String ssid = AndEsptouchHelper.getInstance(this).getWifiSsid();
String ssid = AndEsptouchHelper.getSSID(this);
//获取mac地址
String bssid = AndEsptouchHelper.getInstance(this).getBSSID();
String bssid = AndEsptouchHelper.getBSSID(this);
```
还有其他例如:打开 关闭wifi 判断是否可用。。。

Expand Down
2 changes: 1 addition & 1 deletion andesptouch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def siteUrl = 'https://github.com/Rairmmd/AndEsptouch'
def gitUrl = 'https://github.com/Rairmmd/AndEsptouch.git'

group = "com.rairmmd"
version = "1.0.4"
version = "1.0.5"

android {
compileSdkVersion 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ private AndEsptouchHelper(Context context) {
mWifiInfo = mWifiManager.getConnectionInfo();
}

/**
* 获取SSID
*/
public static String getSSID(Context context) {
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String info = wifiInfo.toString();
String ssid = wifiInfo.getSSID();
if (info.contains(ssid)) {
return ssid;
} else if (ssid.startsWith("\"") && ssid.endsWith("\"")) {
return ssid.substring(1, ssid.length() - 1);
} else {
return ssid;
}
}

/**
* 获取BSSID
*/
public static String getBSSID(Context context) {
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getBSSID();
}

/**
* 获取WifiManager
*/
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// implementation project(':andesptouch')
implementation 'com.rairmmd:andesptouch:1.0.4'
implementation 'com.rairmmd:andesptouch:1.0.5'
}
10 changes: 5 additions & 5 deletions app/src/main/java/com/rair/andesptouch/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void onClick(View v) {
Log.i(TAG, "(MainActivity.java:51)-onClick:->"+ssid);
Log.i(TAG, "(MainActivity.java:51)-onClick:->"+bssid);
Log.i(TAG, "(MainActivity.java:51)-onClick:->"+password);
andEsptouch = new AndEsptouch.Builder(this).setSsid(ssid)
.setBssid(bssid).setPassWord(password).build();
andEsptouch.startEsptouchConfig();
andEsptouch = new AndEsptouch.Builder(this).setSSID(ssid)
.setBSSID(bssid).setPassWord(password).build();
andEsptouch.startConfig();
andEsptouch.setOnEsptouchTaskListener(this);
if (countDownTimer != null) {
countDownTimer = null;
Expand Down Expand Up @@ -99,7 +99,7 @@ private void showProgressDialog(String message) {
@Override
public void onDismiss(DialogInterface dialog) {
if (andEsptouch != null) {
andEsptouch.stopEsptouchConfig();
andEsptouch.stopConfig();
}
}
});
Expand All @@ -116,7 +116,7 @@ private void dismissProgressDialog() {
protected void onDestroy() {
super.onDestroy();
if (andEsptouch != null) {
andEsptouch.stopEsptouchConfig();
andEsptouch.stopConfig();
}
}
}

0 comments on commit 69f0ceb

Please sign in to comment.