version:4.5beta
fix: update:增加获取手机号码,获取运营商类型,获取wifi网络运营商,获取手机号码
This commit is contained in:
@@ -35,6 +35,7 @@ import com.aoleyun.sn.service.LogcatService;
|
||||
import com.aoleyun.sn.utils.ApkUtils;
|
||||
import com.aoleyun.sn.utils.ForegroundAppUtil;
|
||||
import com.aoleyun.sn.utils.JGYUtils;
|
||||
import com.aoleyun.sn.utils.NetworkUtils;
|
||||
import com.aoleyun.sn.utils.SPUtils;
|
||||
import com.aoleyun.sn.utils.ServiceAliveUtils;
|
||||
import com.aoleyun.sn.utils.TimeUtils;
|
||||
@@ -88,10 +89,13 @@ public class SplashActivity extends AppCompatActivity {
|
||||
|
||||
private void initView() {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.e(TAG, "initView: " + Utils.getIMEI(this));
|
||||
Log.e(TAG, "initView: " + Utils.getIMEI(this, 0));
|
||||
Log.e(TAG, "initView: " + Utils.getIMEI(this, 1));
|
||||
|
||||
// Log.e(TAG, "initView: " + Utils.getIMEI(this));
|
||||
// Log.e(TAG, "initView: " + Utils.getIMEI(this, 0));
|
||||
// Log.e(TAG, "initView: " + Utils.getIMEI(this, 1));
|
||||
Log.e(TAG, "getOperators: " + NetworkUtils.getOperators(this));
|
||||
Log.e(TAG, "PublicIP: " + MMKV.defaultMMKV().decodeString(NetInterfaceManager.PublicIP, ""));
|
||||
NetInterfaceManager.GetWhois();
|
||||
Log.e(TAG, "initView: " + NetworkUtils.getPhoneNumber(this));
|
||||
// String jsonString = ApkUtils.getRunningAppInfo(this);
|
||||
// Log.e(TAG, "initView: " + jsonString);
|
||||
ApkUtils.showAllAPP(this);
|
||||
|
||||
@@ -92,7 +92,7 @@ public class CheckNetPresenter implements CheckNetContact.Presenter {
|
||||
|
||||
@Override
|
||||
public void sendMACAddress() {
|
||||
mNetInterfaceManager.sendMACAddress(getLifecycle(), new NetInterfaceManager.onCompleteCallback() {
|
||||
mNetInterfaceManager.sendMACAddress(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
mView.sendMACFinish();
|
||||
|
||||
@@ -153,6 +153,7 @@ public class BaseApplication extends MultiDexApplication {
|
||||
public void onSuccess(Object data, int flag) {
|
||||
//token在设备卸载重装的时候有可能会变
|
||||
Log.e("TPush", "注册成功,设备token为:" + data);
|
||||
MMKV.defaultMMKV().encode("XGPushtoken", data.toString());
|
||||
List<XGPushManager.AccountInfo> accountInfoList = new ArrayList<>();
|
||||
accountInfoList.add(new XGPushManager.AccountInfo(XGPushManager.AccountType.CUSTOM.getValue(), Utils.getSerial(getApplicationContext())));
|
||||
if (Utils.NOSN.equalsIgnoreCase(Utils.getSerial())) {
|
||||
|
||||
109
app/src/main/java/com/aoleyun/sn/bean/WhoisBean.java
Normal file
109
app/src/main/java/com/aoleyun/sn/bean/WhoisBean.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package com.aoleyun.sn.bean;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class WhoisBean implements Serializable {
|
||||
private static final long serialVersionUID = -6537021620041268080L;
|
||||
|
||||
String ip;
|
||||
String pro;
|
||||
String proCode;
|
||||
String city;
|
||||
String cityCode;
|
||||
String region;
|
||||
String regionCode;
|
||||
String addr;
|
||||
String regionNames;
|
||||
String err;
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getPro() {
|
||||
return pro;
|
||||
}
|
||||
|
||||
public void setPro(String pro) {
|
||||
this.pro = pro;
|
||||
}
|
||||
|
||||
public String getProCode() {
|
||||
return proCode;
|
||||
}
|
||||
|
||||
public void setProCode(String proCode) {
|
||||
this.proCode = proCode;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getCityCode() {
|
||||
return cityCode;
|
||||
}
|
||||
|
||||
public void setCityCode(String cityCode) {
|
||||
this.cityCode = cityCode;
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public String getRegionCode() {
|
||||
return regionCode;
|
||||
}
|
||||
|
||||
public void setRegionCode(String regionCode) {
|
||||
this.regionCode = regionCode;
|
||||
}
|
||||
|
||||
public String getAddr() {
|
||||
return addr;
|
||||
}
|
||||
|
||||
public void setAddr(String addr) {
|
||||
this.addr = addr;
|
||||
}
|
||||
|
||||
public String getRegionNames() {
|
||||
return regionNames;
|
||||
}
|
||||
|
||||
public void setRegionNames(String regionNames) {
|
||||
this.regionNames = regionNames;
|
||||
}
|
||||
|
||||
public String getErr() {
|
||||
return err;
|
||||
}
|
||||
|
||||
public void setErr(String err) {
|
||||
this.err = err;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ import com.aoleyun.sn.bean.SnRunLog;
|
||||
import com.aoleyun.sn.bean.SnTimeControl;
|
||||
import com.aoleyun.sn.bean.StudentsInfo;
|
||||
import com.aoleyun.sn.bean.TopApp;
|
||||
import com.aoleyun.sn.bean.WhoisBean;
|
||||
import com.aoleyun.sn.bean.WiFiAlias;
|
||||
import com.aoleyun.sn.comm.CommonConfig;
|
||||
import com.aoleyun.sn.comm.JGYActions;
|
||||
@@ -44,12 +45,13 @@ import com.aoleyun.sn.disklrucache.CacheHelper;
|
||||
import com.aoleyun.sn.gson.NullStringToEmptyAdapterFactory;
|
||||
import com.aoleyun.sn.manager.ConnectManager;
|
||||
import com.aoleyun.sn.manager.ConnectMode;
|
||||
import com.aoleyun.sn.network.api.GetWhoisApi;
|
||||
import com.aoleyun.sn.network.api.get.CheckTestUpdateApi;
|
||||
import com.aoleyun.sn.network.api.get.DefaultAppApi;
|
||||
import com.aoleyun.sn.network.api.get.GetDesktopApi;
|
||||
import com.aoleyun.sn.network.api.get.GetDeveloperApi;
|
||||
import com.aoleyun.sn.network.api.get.GetJpushTagsApi;
|
||||
import com.aoleyun.sn.network.api.get.GetPublicIPApi;
|
||||
import com.aoleyun.sn.network.api.GetPublicIPApi;
|
||||
import com.aoleyun.sn.network.api.get.GetSnRunLogApi;
|
||||
import com.aoleyun.sn.network.api.get.GetWiFiAliasApi;
|
||||
import com.aoleyun.sn.network.api.get.LogoImgApi;
|
||||
@@ -95,6 +97,7 @@ import com.aoleyun.sn.utils.CacheUtils;
|
||||
import com.aoleyun.sn.utils.ForegroundAppUtil;
|
||||
import com.aoleyun.sn.utils.GsonUtils;
|
||||
import com.aoleyun.sn.utils.JGYUtils;
|
||||
import com.aoleyun.sn.utils.NetworkUtils;
|
||||
import com.aoleyun.sn.utils.SPUtils;
|
||||
import com.aoleyun.sn.utils.TimeUtils;
|
||||
import com.aoleyun.sn.utils.ToastUtil;
|
||||
@@ -294,7 +297,7 @@ public class NetInterfaceManager {
|
||||
return mRetrofit.create(MACAddressApi.class)
|
||||
.sendMACaddress(Utils.getSerial(mContext),
|
||||
Utils.getAndroid10MAC(mContext),
|
||||
"0000",
|
||||
MMKV.defaultMMKV().decodeString("XGPushtoken", "未知"),
|
||||
// JPushInterface.getRegistrationID(mContext),
|
||||
Utils.getCustomVersion(),
|
||||
BuildConfig.VERSION_NAME,
|
||||
@@ -302,13 +305,17 @@ public class NetInterfaceManager {
|
||||
Utils.getAPPVersionName(PackageNames.DESKTOP, mContext),
|
||||
Utils.getAndroid7MAC(),
|
||||
Utils.obtainWifiInfo(mContext),
|
||||
(String) SPUtils.get(mContext, "PublicIP", ""),
|
||||
mMMKV.decodeString(NetInterfaceManager.PublicIP, ""),
|
||||
Utils.getIPAddress(mContext),
|
||||
Utils.getBluetoothList(),
|
||||
Utils.getWifiAlias(mContext),
|
||||
Utils.getAPPVersionName(PackageNames.BROWSER, mContext),
|
||||
Utils.getAPPVersionName(PackageNames.NOTIFICATIONS, mContext),
|
||||
JGYUtils.getInstance().getAppPlatform()
|
||||
JGYUtils.getInstance().getAppPlatform(),
|
||||
mMMKV.decodeString(WHOIS_ADDR, "未知"),
|
||||
NetworkUtils.getNetworkType(mContext),
|
||||
NetworkUtils.getOperators(mContext),
|
||||
NetworkUtils.getPhoneNumber(mContext)
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
@@ -1724,21 +1731,41 @@ public class NetInterfaceManager {
|
||||
});
|
||||
}
|
||||
|
||||
String macJson;
|
||||
|
||||
|
||||
/**
|
||||
* 发送mac地址本机信息
|
||||
*
|
||||
* @param lifecycle
|
||||
* @param callback
|
||||
*/
|
||||
public void sendMACAddress(BehaviorSubject<ActivityEvent> lifecycle, onCompleteCallback callback) {
|
||||
String macJson = (String) SPUtils.get(mContext, "macJson", "");
|
||||
String jsonString = JGYUtils.getInstance().getMacJson(mContext);
|
||||
// Log.e(TAG, "sendMACAddress: macJson = " + macJson);
|
||||
// Log.e(TAG, "sendMACAddress: jsonString = " + jsonString);
|
||||
if (macJson.equals(jsonString)) {
|
||||
callback.onComplete();
|
||||
return;
|
||||
public void sendMACAddress(boolean refresh, BehaviorSubject<ActivityEvent> lifecycle, onCompleteCallback callback) {
|
||||
macJson = (String) SPUtils.get(mContext, "macJson", "");
|
||||
String macJsonString = JGYUtils.getInstance().getMacJson(mContext);
|
||||
|
||||
ConnectMode connectMode = ConnectMode.ONE_HOUR;
|
||||
if (refresh) {
|
||||
connectMode = ConnectMode.DEFAULT;
|
||||
}
|
||||
if (ConnectManager.getInstance().isNeedConnect(UrlAddress.SEND_DEVICES, connectMode)) {
|
||||
if (macJson.equals(macJsonString)) {
|
||||
callback.onComplete();
|
||||
} else {
|
||||
sendMACAddress(lifecycle, callback);
|
||||
}
|
||||
} else {
|
||||
String jsonString = cacheHelper.getAsString(UrlAddress.SEND_DEVICES);
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
sendMACAddress(lifecycle, callback);
|
||||
} else {
|
||||
callback.onComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMACAddress(BehaviorSubject<ActivityEvent> lifecycle, onCompleteCallback callback) {
|
||||
sendMACAddressObservable()
|
||||
.observeOn(Schedulers.io())
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
@@ -1751,8 +1778,9 @@ public class NetInterfaceManager {
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse response) {
|
||||
if (response.code == OK) {
|
||||
cacheHelper.put(UrlAddress.SEND_DEVICES, macJson);
|
||||
Log.e("sendMACAddress", response.msg);
|
||||
SPUtils.put(mContext, "macJson", JGYUtils.getInstance().getMacJson(mContext));
|
||||
SPUtils.put(mContext, "macJson", macJson);
|
||||
} else {
|
||||
Log.e("sendMACAddress", response.toString());
|
||||
}
|
||||
@@ -1774,6 +1802,7 @@ public class NetInterfaceManager {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
synchronized public void setPushTags(boolean refresh, BehaviorSubject<ActivityEvent> lifecycle, onCompleteCallback callback) {
|
||||
ConnectMode connectMode = ConnectMode.ONE_HOUR;
|
||||
if (refresh) {
|
||||
@@ -3064,9 +3093,10 @@ public class NetInterfaceManager {
|
||||
|
||||
public interface PublicIP {
|
||||
void set(String ip);
|
||||
|
||||
}
|
||||
|
||||
public static final String PublicIP = "PublicIP";
|
||||
|
||||
/**
|
||||
* 获取设备公网IP
|
||||
*
|
||||
@@ -3121,8 +3151,48 @@ public class NetInterfaceManager {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getPublicIP", "onComplete: ");
|
||||
MMKV.defaultMMKV().encode(NetInterfaceManager.PublicIP, IpAddr);
|
||||
publicIP.set(IpAddr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static final String WHOIS_ADDR = "whois_ip_addr";
|
||||
|
||||
public static void GetWhois() {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.client(NetInterfaceManager.getInstance().getOkHttpClient())
|
||||
.baseUrl(UrlAddress.PCONLINE_WHOIS)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
|
||||
.build();
|
||||
retrofit.create(GetWhoisApi.class)
|
||||
.getWhois(true)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<WhoisBean>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("GetWhois", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull WhoisBean whoisBean) {
|
||||
Log.e("GetWhois", "onNext: " + whoisBean);
|
||||
if (whoisBean != null && !TextUtils.isEmpty(whoisBean.getAddr())) {
|
||||
MMKV.defaultMMKV().encode(WHOIS_ADDR, whoisBean.getAddr());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("GetWhois", "onError: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("GetWhois", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +118,10 @@ public class UrlAddress {
|
||||
|
||||
/*获取公网IP*/
|
||||
public static final String SHOUHU_CITYJSON = "http://pv.sohu.com/cityjson/";
|
||||
/*通过ip获取信息*/
|
||||
public static final String PCONLINE_WHOIS = "http://whois.pconline.com.cn/";
|
||||
public static final String WHOIS = "ipJson.jsp";
|
||||
|
||||
|
||||
/*删除alias*/
|
||||
public static final String DELETE_JPUSH_ALIAS = "https://device.jpush.cn/v3/aliases/";
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.aoleyun.sn.network.api.get;
|
||||
package com.aoleyun.sn.network.api;
|
||||
|
||||
import com.aoleyun.sn.bean.BaseResponse;
|
||||
import com.aoleyun.sn.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
/**
|
||||
* @author : fanhuitong
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.aoleyun.sn.network.api;
|
||||
|
||||
import com.aoleyun.sn.bean.WhoisBean;
|
||||
import com.aoleyun.sn.network.UrlAddress;
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
/**
|
||||
* @author : fanhuitong
|
||||
* e-mail :
|
||||
* @date : 2021/10/1814:39
|
||||
* desc :
|
||||
* version: 1.0
|
||||
*/
|
||||
public interface GetWhoisApi {
|
||||
@GET(UrlAddress.WHOIS)
|
||||
Observable<WhoisBean> getWhois(
|
||||
@Query("json") boolean json
|
||||
);
|
||||
}
|
||||
@@ -29,6 +29,10 @@ public interface MACAddressApi {
|
||||
@Field("wifi_name") String wifi_name,
|
||||
@Field("browser_version") String browser_version,
|
||||
@Field("notice_version") String notice_version,
|
||||
@Field("platform") String platform
|
||||
@Field("platform") String platform,
|
||||
@Field("wifi_operator") String wifi_operator,
|
||||
@Field("network_type") String network_type,
|
||||
@Field("network_operator") String network_operator,
|
||||
@Field("sn_phone") String sn_phone
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.aoleyun.sn.network.interceptor;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.aoleyun.sn.BuildConfig;
|
||||
import com.aoleyun.sn.utils.MD5Util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -30,7 +31,7 @@ public class RepeatRequestInterceptor implements Interceptor {
|
||||
long time = System.currentTimeMillis();//请求时间
|
||||
try {
|
||||
if (requestIdsMap.size() > 0 && requestIdsMap.containsKey(requestKey)) {
|
||||
Log.e("REPEAT-REQUEST", "重复请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url() + "\t" + bodyToString(request));
|
||||
log(requestKey, request);
|
||||
//下面这行写了不会抛出onerror
|
||||
// chain.call().cancel();
|
||||
return new Response.Builder()
|
||||
@@ -39,7 +40,7 @@ public class RepeatRequestInterceptor implements Interceptor {
|
||||
.build();
|
||||
}
|
||||
requestIdsMap.put(requestKey, time);
|
||||
Log.e("REPEAT-REQUEST", "注册请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url() + "\t" + bodyToString(request));
|
||||
log(requestKey, request);
|
||||
// RepeatRequestInterceptor.Builder builder = request.newBuilder();
|
||||
// builder.addHeader("header", jsonObject.toString());
|
||||
return chain.proceed(request);
|
||||
@@ -49,18 +50,26 @@ public class RepeatRequestInterceptor implements Interceptor {
|
||||
} finally {
|
||||
if (requestIdsMap.containsKey(requestKey) && requestIdsMap.containsValue(time)) {//请求任务完成删除map中的数据
|
||||
requestIdsMap.remove(requestKey);
|
||||
Log.e("REPEAT-REQUEST", "移除请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url() + "\t" + bodyToString(request));
|
||||
log(requestKey, request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String bodyToString(final Request request){
|
||||
private void log(String requestKey, Request request) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.e("REPEAT-REQUEST", "移除请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url() + "\t" + bodyToString(request));
|
||||
} else {
|
||||
Log.e("REPEAT-REQUEST", "移除请求:" + requestKey + " Method @" + request.method());
|
||||
}
|
||||
}
|
||||
|
||||
private static String bodyToString(final Request request) {
|
||||
try {
|
||||
final Request copy = request.newBuilder().build();
|
||||
final Buffer buffer = new Buffer();
|
||||
copy.body().writeTo(buffer);
|
||||
return buffer.readUtf8();
|
||||
} catch ( Exception e) {
|
||||
} catch (Exception e) {
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class MainSPresenter implements MainSContact.Presenter {
|
||||
|
||||
@Override
|
||||
public void sendMACAddress() {
|
||||
NetInterfaceManager.getInstance().sendMACAddress(getLifecycle(), new NetInterfaceManager.onCompleteCallback() {
|
||||
NetInterfaceManager.getInstance().sendMACAddress(true, getLifecycle(), new NetInterfaceManager.onCompleteCallback() {
|
||||
@Override
|
||||
public void onComplete() {
|
||||
mView.sendMACFinish();
|
||||
|
||||
@@ -65,6 +65,7 @@ import com.aoleyun.sn.service.GuardService;
|
||||
import com.aoleyun.sn.service.LogcatService;
|
||||
import com.aoleyun.sn.service.main.MainService;
|
||||
import com.aoleyun.sn.service.StepService;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -1965,7 +1966,7 @@ public class JGYUtils {
|
||||
jsonObject.addProperty("desktop_version", Utils.getAPPVersionName("com.aoleyun.os", mContext));
|
||||
jsonObject.addProperty("local_mac", Utils.getAndroid7MAC());
|
||||
// jsonObject.addProperty("wifi_status", Utils.obtainWifiInfo(mContext));
|
||||
jsonObject.addProperty("PN_ip", (String) SPUtils.get(mContext, "PublicIP", ""));
|
||||
jsonObject.addProperty("PN_ip", MMKV.defaultMMKV().decodeString(NetInterfaceManager.PublicIP, ""));
|
||||
jsonObject.addProperty("LAN_ip", Utils.getIPAddress(mContext));
|
||||
jsonObject.addProperty("bluetooth", Utils.getBluetoothList());
|
||||
jsonObject.addProperty("wifi_name", Utils.getWifiAlias(mContext));
|
||||
|
||||
@@ -1,15 +1,31 @@
|
||||
package com.aoleyun.sn.utils;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.telephony.CellInfo;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fanhuitong
|
||||
*/
|
||||
public class NetworkUtils {
|
||||
private static String TAG = NetworkUtils.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* 网络是否连接
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static boolean isConnected(Context context) {
|
||||
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
@@ -29,7 +45,13 @@ public class NetworkUtils {
|
||||
}
|
||||
|
||||
|
||||
public String getNetworkType(Context context) {
|
||||
/**
|
||||
* 获取网络类型
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static String getNetworkType(Context context) {
|
||||
String strNetworkType = "UnKnown";
|
||||
final NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
|
||||
if (activeNetworkInfo != null && activeNetworkInfo.getType() == 1) {
|
||||
@@ -67,7 +89,49 @@ public class NetworkUtils {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Log.e(TAG, "getNetworkType: " + strNetworkType);
|
||||
return strNetworkType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取SIM卡运营商
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static String getOperators(Context context) {
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1; i <= tm.getPhoneCount(); i++) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("SIM卡").append(i).append(":");
|
||||
String operatorName = tm.getSimOperatorName(i);
|
||||
sb.append(TextUtils.isEmpty(operatorName) ? "未知" : operatorName);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取电话号码
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
@SuppressLint("HardwareIds")
|
||||
public static String getPhoneNumber(Context context) {
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1; i <= tm.getPhoneCount(); i++) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
// sb.append("电话").append(i).append(":");
|
||||
String operatorName = tm.getLine1Number(i);
|
||||
sb.append(TextUtils.isEmpty(operatorName) ? "未知" : operatorName);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ import com.google.zxing.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -1649,7 +1650,6 @@ public class Utils {
|
||||
NetInterfaceManager.getPublicIP(new NetInterfaceManager.PublicIP() {
|
||||
@Override
|
||||
public void set(String ip) {
|
||||
SPUtils.put(context, "PublicIP", ip);
|
||||
Log.e("getPublicIP", "set: " + ip);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user