diff --git a/android_crop_lib/build.gradle b/android_crop_lib/build.gradle
index a52b7c7a3..ce6b7de3c 100644
--- a/android_crop_lib/build.gradle
+++ b/android_crop_lib/build.gradle
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
- compileSdkVersion 29
+ compileSdkVersion 30
defaultConfig {
minSdkVersion 21
@@ -19,7 +19,7 @@ android {
}
}
- buildToolsVersion = '28.0.3'
+ buildToolsVersion = '30.0.3'
}
dependencies {
diff --git a/app/and_res_guard.gradle b/app/and_res_guard.gradle
deleted file mode 100644
index 4c6283ba1..000000000
--- a/app/and_res_guard.gradle
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * *************************************
- * android 资源混淆脚本
- ***************************************
- */
-apply plugin: 'AndResGuard'
-
-
-andResGuard {
- mappingFile = file("./resource_mapping.txt")
-// mappingFile = null
- // 当你使用v2签名的时候,7zip压缩是无法生效的。
- use7zip = false
- useSign = true
- // 打开这个开关,会keep住所有资源的原始路径,只混淆资源的名字
- keepRoot = false
- whiteList = [
- // for your icon
- "R.mipmap.app_logo",
- // for fabric
- "R.string.com.crashlytics.*",
- //sharesdk
- "R.string.ssdk_*",
- "R.string.smssdk_*",
- "R.layout.ssdk_*",
- "R.drawable.ssdk_*",
- "R.mipmap.ssdk_*",
- "R.anim.ssdk_*",
- "R.color.ssdk_*",
- "R.style.ssdk_*",
- "R.id.ssdk_*",
- //ktv
- "R.id.sb_accompany_voice",
- "R.id.tv_accompany_voice",
- "R.id.sb_person_voice",
- "R.id.tv_person_voice",
- "R.id.tv_change_audio",
- "R.id.iv_play_or_pause",
- "R.id.cv_people_sound",
- "R.id.cv_accompany_sound",
- "R.id.layout_song_progress",
- // for google-services
- "R.string.google_app_id",
- "R.string.gcm_defaultSenderId",
- "R.string.default_web_client_id",
- "R.string.ga_trackingId",
- "R.string.firebase_database_url",
- "R.string.google_api_key",
- "R.string.google_crash_reporting_api_key",
- //for aliyun RPSDK
- "R.drawable.yw_1222_*",
- //for voice match
- "R.id.iv_group_like",
- "R.id.iv_group_dont_like",
- "R.id.fl_group_content",
- "R.id.svga_group_voice_like",
- //for yidun
- "R.drawable.bg_quick_pass*",
- "R.drawable.quick_pass_*",
- //for yidun liantong
- "R.layout.activity_oauth",
- "R.id.oauth_back",
- "R.id.is_agree",
- "R.id.oauth_title",
- "R.id.app_name",
- "R.id.oauth_mobile_et",
- "R.id.oauth_login",
- "R.id.service_and_privacy",
- "R.id.authorize_app",
- "R.id.brand",
- "R.id.navigation_bar_line",
- "R.id.oauth_logo",
- "R.id.navigation_bar",
- "R.id.protocol",
- "R.id.oauth_content",
- "R.id.other_login",
- "R.id.login_before_text",
-
- "R.layout.oauth_loading_dialog",
- "R.id.oauth_loading_dialog_txt",
- "R.id.loading_parent",
- "R.id.oauth_loading_dialog_img",
- //for yidongka
- "R.anim.umcsdk_*",
- "R.drawable.dialog_loading",
- "R.drawable.umcsdk_*",
- "R.drawable.loading",
- "R.string.umcsdk_*",
- //华为推送
- "R.string.hms*",
- "R.string.connect_server_fail_prompt_toast",
- "R.string.getting_message_fail_prompt_toast",
- "R.string.no_available_network_prompt_toast",
- "R.string.third_app_*",
- "R.string.upsdk_*",
- "R.layout.hms*",
- "R.layout.upsdk_*",
- "R.drawable.upsdk*",
- "R.color.upsdk*",
- "R.dimen.upsdk*",
- "R.style.upsdk*",
- "R.string.agc*"
- ]
- compressFilePattern = [
- "*.png",
- "*.jpg",
- "*.jpeg",
- "*.gif",
- "resources.arsc"
- ]
- sevenzip {
- artifact = 'com.tencent.mm:SevenZip:1.2.15'
- //path = "/usr/local/bin/7za"
- }
-
- // erban-${variant.buildType.name}-${defaultConfig.versionName}_${defaultConfig.versionCode}-${releaseTime()}-${variant.productFlavors[0].name}.apk".toLowerCase())
-// sourceApk = "${project.rootDir}/耳伴-${buildTypes}-${defaultConfig.versionName}_${defaultConfig.versionCode}-${releaseTime()}.apk".toLowerCase()
-
- /**
- * 可选: 指定v1签名时生成jar文件的摘要算法
- * 默认值为“SHA-1”
- **/
- // digestalg = "SHA-256"
-}
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 0b489070b..59d97e0c1 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,14 +1,13 @@
apply plugin: 'com.android.application'
-// android res guard 资源混淆脚本
-apply from: 'and_res_guard.gradle'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.huawei.agconnect'
+apply plugin: 'com.tencent.vasdolly'
android {
- compileSdkVersion 29
+ compileSdkVersion 30
defaultConfig {
applicationId "com.mango.yinyou"
@@ -44,11 +43,6 @@ android {
disable 'ExtraTranslation'
}
- dexOptions {
- javaMaxHeapSize "1g"
- jumboMode = true
- }
-
dataBinding {
enabled = true
}
@@ -145,18 +139,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
- staging {
- buildConfigField "String", "BASE_URL", "\"https://api.lecheng163.com/\""
- buildConfigField "String", "BASE_URL_DEBUG", "BASE_URL"
- buildConfigField "String", "BASE_URL_STAGING", "BASE_URL"
- buildConfigField "String", "BASE_URL_RELEASE", "BASE_URL"
- minifyEnabled true
- shrinkResources true
- signingConfig signingConfigs.v2
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- matchingFallbacks = ['staging', 'release']
- }
-
debug {
buildConfigField "String", "BASE_URL", "\"http://api.uat.lecheng163.com/\""
buildConfigField "String", "BASE_URL_DEBUG", "BASE_URL"
@@ -179,17 +161,11 @@ android {
jvmTarget = "1.8"
}
- productFlavors {
- accompany {
- dimension 'default'
- manifestPlaceholders = [CHANNEL_VALUE: channel]
- }
- }
- buildToolsVersion = '28.0.3'
+ buildToolsVersion = '30.0.3'
}
-def Lombok = "1.16.20"
+def Lombok = "1.18.10"
def useFlutterAar = Boolean.parseBoolean(with_flutter_aar)
dependencies {
@@ -217,8 +193,8 @@ dependencies {
api "com.github.yyued:SVGAPlayer-Android:2.6.1"
implementation "com.orhanobut:logger:2.2.0"
api "com.ms-square:expandableTextView:0.1.4"
- api "com.jakewharton:butterknife:10.1.0"
- annotationProcessor "com.jakewharton:butterknife-compiler:10.1.0"
+ api "com.jakewharton:butterknife:10.2.3"
+ annotationProcessor "com.jakewharton:butterknife-compiler:10.2.3"
implementation "com.llew.huawei:verifier:1.0.3"
annotationProcessor 'androidx.annotation:annotation:1.1.0'
@@ -289,6 +265,8 @@ dependencies {
implementation project(path: ':flutter')
implementation project(path: ':flutter_boost')
}
+
+ api 'com.tencent.vasdolly:helper:3.0.3'
}
String storageUrl = System.env.FLUTTER_STORAGE_BASE_URL ?: "https://storage.googleapis.com"
@@ -307,3 +285,16 @@ repositories {
url "$storageUrl/download.flutter.io"
}
}
+
+channel{
+ //多渠道包的输出目录,默认为new File(project.buildDir,"channel")
+ outputDir = new File(project.buildDir,"channelapk")
+ //多渠道包的命名规则,默认为:${appName}-${versionName}-${versionCode}-${flavorName}-${buildType}-${buildTime}
+ apkNameFormat ='${appName}-${buildType}-${flavorName}-${versionName}-${buildTime}'
+ //快速模式:生成渠道包时不进行校验(速度可以提升10倍以上,默认为false)
+ fastMode = false
+ //buildTime的时间格式,默认格式:yyyyMMdd-HHmmss
+ buildTimeDateFormat = 'MMddHHmm'
+ //低内存模式(仅针对V2签名,默认为false):只把签名块、中央目录和EOCD读取到内存,不把最大头的内容块读取到内存,在手机上合成APK时,可以使用该模式
+ lowMemory = false
+}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 60ba06dbb..e2a46b13b 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -91,10 +91,6 @@
android:usesCleartextTraffic="true"
tools:replace="android:name,android:allowBackup">
-
-
- * Created by huangjun on 2017/6/22.
- */
-
-public class TemplateRoot extends ElementGroup {
- // attr
- private String templateId; // 模板编号
- private String globalParams; // 全局变量
- private String version; // 协议版本号
-
- // log
- private String jsonString; // xml2JsonString
-
- public TemplateRoot(String xml) {
- try {
- if (!xml.contains(ElementTag.XML_HEADER_PREFIX)) {
- xml = ElementTag.XML_HEADER + xml;
- }
- JSONObject rootJsonObject = XML.toJSONObject(xml);
- parse(rootJsonObject);
- jsonString = rootJsonObject.toString();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void parse(JSONObject rootJsonObject) throws JSONException {
- JSONObject jsonObject = rootJsonObject.getJSONObject(ElementTag.ELEMENT_LABEL_TEMPLATE);
-
- templateId = jsonObject.optString(ElementTag.ELEMENT_ATTRIBUTE_ID);
- globalParams = jsonObject.optString(ElementTag.ELEMENT_ATTRIBUTE_PARAMS);
- version = jsonObject.optString(ElementTag.ELEMENT_ATTRIBUTE_VERSION);
-
- if (jsonObject.has(ElementTag.ELEMENT_LABEL_LINEAR_LAYOUT)) {
-
- JSONObject object = jsonObject.optJSONObject(ElementTag.ELEMENT_LABEL_LINEAR_LAYOUT);
- if (object != null) {
- LinearLayout linearLayout = new LinearLayout();
- linearLayout.parse(object);
- addElement(linearLayout);
- } else {
- JSONArray array = jsonObject.optJSONArray(ElementTag.ELEMENT_LABEL_LINEAR_LAYOUT);
- if (array != null && array.length() > 0) {
- for (int i = 0; i < array.length(); i++) {
- JSONObject obj = array.getJSONObject(i);
- LinearLayout linearLayout = new LinearLayout();
- linearLayout.parse(obj);
- addElement(linearLayout);
- }
- }
- }
- }
- }
-
- public String getTemplateId() {
- return templateId;
- }
-
- public String getGlobalParams() {
- return globalParams;
- }
-
- public String getVersion() {
- return version;
- }
-
- @Override
- public String toString() {
- return jsonString;
- }
-}
diff --git a/nim_uikit/src/com/netease/nim/uikit/business/session/viewholder/robot/RobotContentLinearLayout.java b/nim_uikit/src/com/netease/nim/uikit/business/session/viewholder/robot/RobotContentLinearLayout.java
index 397a8c997..089af501b 100644
--- a/nim_uikit/src/com/netease/nim/uikit/business/session/viewholder/robot/RobotContentLinearLayout.java
+++ b/nim_uikit/src/com/netease/nim/uikit/business/session/viewholder/robot/RobotContentLinearLayout.java
@@ -13,7 +13,6 @@ import com.netease.nim.uikit.business.robot.parser.elements.base.Element;
import com.netease.nim.uikit.business.robot.parser.elements.element.ImageElement;
import com.netease.nim.uikit.business.robot.parser.elements.element.TextElement;
import com.netease.nim.uikit.business.robot.parser.elements.group.LinkElement;
-import com.netease.nim.uikit.business.robot.parser.elements.group.TemplateRoot;
import java.util.ArrayList;
import java.util.List;
@@ -66,7 +65,7 @@ public class RobotContentLinearLayout extends LinearLayout {
for (RobotBotContent bot : botContents) {
if (RobotResponseContent.RES_TYPE_BOT_COMP.equals(bot.getType())) {
// 复合
- convertTemplateToViews(new TemplateRoot(bot.getBotMsg()), robot);
+ // convertTemplateToViews(new TemplateRoot(bot.getBotMsg()), robot);
} else if (RobotResponseContent.RES_TYPE_BOT_TEXT.equals(bot.getType())
|| RobotResponseContent.RES_TYPE_BOT_QUICK.equals(bot.getType())) {
// 文本
@@ -85,38 +84,6 @@ public class RobotContentLinearLayout extends LinearLayout {
bindChildContentViews();
}
- private void convertTemplateToViews(final TemplateRoot template, final ClickableChildView robot) {
- List robotLinearLayouts = template.getElements();
- if (robotLinearLayouts == null) {
- return;
- }
- for (com.netease.nim.uikit.business.robot.parser.elements.group.LinearLayout robotLinearLayout : robotLinearLayouts) {
- int size = robotLinearLayout.getElements().size();
- if (size <= 0) {
- continue;
- }
- for (int i = 0; i < size; i++) {
- RobotViewBase view;
- Element e = robotLinearLayout.getElements().get(i);
- if (e instanceof TextElement) {
- view = RobotViewFactory.createRobotTextView(getContext(), (TextElement) e, null);
- } else if (e instanceof ImageElement) {
- view = RobotViewFactory.createRobotImageView(getContext(), (ImageElement) e, null);
- } else if (e instanceof LinkElement) {
- view = RobotViewFactory.createRobotLinkView(getContext(), (LinkElement) e);
- if (linkViewStyle != null) {
- ((RobotLinkView) view).setLinkViewStyle(linkViewStyle);
- }
- view.setId(GenerateViewID.generateViewId());
- robot.addClickableChildView(RobotLinkView.class, view.getId());
- } else {
- continue;
- }
-
- robotViews.add(view);
- }
- }
- }
private void bindChildContentViews() {
removeAllViews();
diff --git a/nim_uikit/src/com/netease/nim/uikit/common/util/sys/NetworkUtil.java b/nim_uikit/src/com/netease/nim/uikit/common/util/sys/NetworkUtil.java
index 206337b1e..cab247aa7 100644
--- a/nim_uikit/src/com/netease/nim/uikit/common/util/sys/NetworkUtil.java
+++ b/nim_uikit/src/com/netease/nim/uikit/common/util/sys/NetworkUtil.java
@@ -1,197 +1,14 @@
package com.netease.nim.uikit.common.util.sys;
import android.content.Context;
-import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
-import android.net.Uri;
-import android.net.wifi.WifiInfo;
-import android.net.wifi.WifiManager;
-import android.os.Build;
import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-
-import com.netease.nim.uikit.common.util.log.LogUtil;
public class NetworkUtil {
public static final String TAG = "NetworkUtil";
- public static final byte CURRENT_NETWORK_TYPE_NONE = 0;
-
- /*
- * 根据APN区分网络类型
- */
- public static final byte CURRENT_NETWORK_TYPE_WIFI = 1;// wifi
-
- public static final byte CURRENT_NETWORK_TYPE_CTNET = 2;// ctnet
-
- public static final byte CURRENT_NETWORK_TYPE_CTWAP = 3;// ctwap
-
- public static final byte CURRENT_NETWORK_TYPE_CMWAP = 4;// cmwap
-
- public static final byte CURRENT_NETWORK_TYPE_UNIWAP = 5;// uniwap,3gwap
-
- public static final byte CURRENT_NETWORK_TYPE_CMNET = 6;// cmnet
-
- public static final byte CURRENT_NETWORK_TYPE_UNIET = 7;// uninet,3gnet
-
- /**
- * 根据运营商区分网络类型
- */
- public static final byte CURRENT_NETWORK_TYPE_CTC = 10;// ctwap,ctnet
-
- public static final byte CURRENT_NETWORK_TYPE_CUC = 11;// uniwap,3gwap,uninet,3gnet
-
- public static final byte CURRENT_NETWORK_TYPE_CM = 12;// cmwap,cmnet
-
- /**
- * apn值
- */
- private static final String CONNECT_TYPE_WIFI = "wifi";
-
- private static final String CONNECT_TYPE_CTNET = "ctnet";
-
- private static final String CONNECT_TYPE_CTWAP = "ctwap";
-
- private static final String CONNECT_TYPE_CMNET = "cmnet";
-
- private static final String CONNECT_TYPE_CMWAP = "cmwap";
-
- private static final String CONNECT_TYPE_UNIWAP = "uniwap";
-
- private static final String CONNECT_TYPE_UNINET = "uninet";
-
- private static final String CONNECT_TYPE_UNI3GWAP = "3gwap";
-
- private static final String CONNECT_TYPE_UNI3GNET = "3gnet";
-
- private static final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
-
- public static byte curNetworkType = CURRENT_NETWORK_TYPE_NONE;
-
- /*
- *
- * 获取网络类型
- *
- */
- public static int getNetType(Context context) {
- NetworkInfo networkInfo = getActiveNetworkInfo(context);
- if (networkInfo == null) {
- return -1;
- } else
- return networkInfo.getType();
- }
-
-
- /**
- * 判断当前网络类型。WIFI,NET,WAP
- *
- * @param context
- * @return
- */
- public static byte getCurrentNetType(Context context) {
- NetworkInfo networkInfo = getActiveNetworkInfo(context);
- byte type = CURRENT_NETWORK_TYPE_NONE;
- if (networkInfo != null) {
- // String typeName = networkInfo.getTypeName();
- // XT800
- String typeName = networkInfo.getExtraInfo();
- if (TextUtils.isEmpty(typeName)) {
- typeName = networkInfo.getTypeName();
- }
- if (!TextUtils.isEmpty(typeName)) {
- String temp = typeName.toLowerCase();
- if (temp.indexOf(CONNECT_TYPE_WIFI) > -1) {// wifi
- type = CURRENT_NETWORK_TYPE_WIFI;
- } else if (temp.indexOf(CONNECT_TYPE_CTNET) > -1) {// ctnet
- type = CURRENT_NETWORK_TYPE_CTNET;
- } else if (temp.indexOf(CONNECT_TYPE_CTWAP) > -1) {// ctwap
- type = CURRENT_NETWORK_TYPE_CTWAP;
- } else if (temp.indexOf(CONNECT_TYPE_CMNET) > -1) {// cmnet
- type = CURRENT_NETWORK_TYPE_CMNET;
- } else if (temp.indexOf(CONNECT_TYPE_CMWAP) > -1) {// cmwap
- type = CURRENT_NETWORK_TYPE_CMWAP;
- } else if (temp.indexOf(CONNECT_TYPE_UNIWAP) > -1) {// uniwap
- type = CURRENT_NETWORK_TYPE_UNIWAP;
- } else if (temp.indexOf(CONNECT_TYPE_UNI3GWAP) > -1) {// 3gwap
- type = CURRENT_NETWORK_TYPE_UNIWAP;
- } else if (temp.indexOf(CONNECT_TYPE_UNINET) > -1) {// uninet
- type = CURRENT_NETWORK_TYPE_UNIET;
- } else if (temp.indexOf(CONNECT_TYPE_UNI3GNET) > -1) {// 3gnet
- type = CURRENT_NETWORK_TYPE_UNIET;
- }
- }
- }
-
- if (type == CURRENT_NETWORK_TYPE_NONE) {
- String apnType = getApnType(context);
- if (apnType != null && apnType.equals(CONNECT_TYPE_CTNET)) {// ctnet
- type = CURRENT_NETWORK_TYPE_CTNET;
- } else if (apnType != null && apnType.equals(CONNECT_TYPE_CTWAP)) {// ctwap
- type = CURRENT_NETWORK_TYPE_CTWAP;
- } else if (apnType != null && apnType.equals(CONNECT_TYPE_CMWAP)) {// cmwap
- type = CURRENT_NETWORK_TYPE_CMWAP;
- } else if (apnType != null && apnType.equals(CONNECT_TYPE_CMNET)) {// cmnet
- type = CURRENT_NETWORK_TYPE_CMNET;
- } else if (apnType != null && apnType.equals(CONNECT_TYPE_UNIWAP)) {// uniwap
- type = CURRENT_NETWORK_TYPE_UNIWAP;
- } else if (apnType != null && apnType.equals(CONNECT_TYPE_UNI3GWAP)) {// 3gwap
- type = CURRENT_NETWORK_TYPE_UNIWAP;
- } else if (apnType != null && apnType.equals(CONNECT_TYPE_UNINET)) {// uninet
- type = CURRENT_NETWORK_TYPE_UNIET;
- } else if (apnType != null && apnType.equals(CONNECT_TYPE_UNI3GNET)) {// 3gnet
- type = CURRENT_NETWORK_TYPE_UNIET;
- }
- }
- curNetworkType = type;
-
- return type;
- }
-
- /**
- * 判断APNTYPE
- *
- * @param context
- * @return
- */
- /**
- * @deprecated 4.0
- * doc:
- * Since the DB may contain corp passwords, we should secure it. Using the same permission as writing to the DB as the read is potentially as damaging as a write
- */
- public static String getApnType(Context context) {
-
- String apntype = "nomatch";
- Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
- if (c != null) {
- if (c.moveToFirst()) {
- String user = c.getString(c.getColumnIndex("user"));
- if (user != null && user.startsWith(CONNECT_TYPE_CTNET)) {
- apntype = CONNECT_TYPE_CTNET;
- } else if (user != null && user.startsWith(CONNECT_TYPE_CTWAP)) {
- apntype = CONNECT_TYPE_CTWAP;
- } else if (user != null && user.startsWith(CONNECT_TYPE_CMWAP)) {
- apntype = CONNECT_TYPE_CMWAP;
- } else if (user != null && user.startsWith(CONNECT_TYPE_CMNET)) {
- apntype = CONNECT_TYPE_CMNET;
- } else if (user != null && user.startsWith(CONNECT_TYPE_UNIWAP)) {
- apntype = CONNECT_TYPE_UNIWAP;
- } else if (user != null && user.startsWith(CONNECT_TYPE_UNINET)) {
- apntype = CONNECT_TYPE_UNINET;
- } else if (user != null && user.startsWith(CONNECT_TYPE_UNI3GWAP)) {
- apntype = CONNECT_TYPE_UNI3GWAP;
- } else if (user != null && user.startsWith(CONNECT_TYPE_UNI3GNET)) {
- apntype = CONNECT_TYPE_UNI3GNET;
- }
- }
- c.close();
- c = null;
- }
-
- return apntype;
- }
-
/**
* 判断是否有网络可用
*
@@ -207,22 +24,6 @@ public class NetworkUtil {
}
}
- /**
- * 此判断不可靠
- *
- * @param context
- * @return
- */
- public static boolean isNetworkConnected(Context context) {
- NetworkInfo networkInfo = getActiveNetworkInfo(context);
- if (networkInfo != null) {
- boolean a = networkInfo.isConnected();
- return a;
- } else {
- return false;
- }
- }
-
/**
* 获取可用的网络信息
*
@@ -238,50 +39,6 @@ public class NetworkUtil {
}
}
- public static boolean isWifiOr3G(Context context) {
- if (isWifi(context)) {
- return true;
- } else {
- return is3G(context);
- }
- }
-
- public static boolean is2G(Context context) {
- return !isWifiOr3G(context);
- }
-
- public static boolean is3G(Context context) {
- int type = getNetworkClass(context);
- if (type == NETWORK_CLASS_3_G || type == NETWORK_CLASS_4_G) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * 当前网络是否是wifi网络
- *
- * @param context
- * @return
- */
- public static boolean isWifi(Context context) {
- try {
- ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo ni = cm.getActiveNetworkInfo();
- if (ni != null) {
- if (ni.getType() == ConnectivityManager.TYPE_WIFI) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- } catch (Exception e) {
- return false;
- }
- }
public static boolean getNetworkConnectionStatus(Context context) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -307,559 +64,4 @@ public class NetworkUtil {
}
}
- public static String getNetworkProxyInfo(Context context) {
- String proxyHost = android.net.Proxy.getDefaultHost();
- int proxyPort = android.net.Proxy.getDefaultPort();
- String szport = String.valueOf(proxyPort);
- String proxyInfo = null;
-
- ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- if (manager == null) {
- return null;
- } else {
- NetworkInfo info = manager.getActiveNetworkInfo();
- if (info != null) {
- String typeName = info.getTypeName().toLowerCase();
- if (typeName != null && typeName.equals("wifi")) {
- return null;
- }
- } else {
- return null;
- }
- }
-
- if (proxyHost != null && (0 < proxyPort && proxyPort < 65535)) {
- proxyInfo = proxyHost + ":" + szport;
- return proxyInfo;
- } else {
- return null;
- }
- }
-
- public static String getNetworkProxyUrl(Context context) {
- if (isWifi(context)) {
- return null;
- }
-
- String proxyHost = android.net.Proxy.getDefaultHost();
- LogUtil.e(TAG, "proxyHost:" + proxyHost);
- return proxyHost;
- }
-
- public static String getNetworkProxyUrl() {
- /**
- * 当网络为wifi时,直接返回空代理: 当ctwap,cmwap,uniwap,3gwap开启时同时开启wifi网络
- * ,通过下面的getDefaultHost接口将得到对应wap网络代理ip ,这是错误的,所以在此判断当前网络是否为wifi
- */
- if (curNetworkType == CURRENT_NETWORK_TYPE_WIFI) {
- return null;
- }
-
- String proxyHost = android.net.Proxy.getDefaultHost();
- LogUtil.e(TAG, "proxyHost:" + proxyHost);
- return proxyHost;
- }
-
- public static int getNetworkProxyPort() {
- int proxyPort = android.net.Proxy.getDefaultPort();
- return proxyPort;
- }
-
- public static boolean isCtwap(Context context) {
- if (getApnType(context).equals(CONNECT_TYPE_CTWAP)) {
- return true;
- } else {
- return false;
- }
- }
-
- public static boolean isUniwap(Context context) {
- if (getApnType(context).equals(CONNECT_TYPE_UNIWAP)) {
- return true;
- } else {
- return false;
- }
- }
-
- public static boolean isCmwap(Context context) {
- if (getApnType(context).equals(CONNECT_TYPE_CMWAP)) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * 判断是否是电信网络(ctwap,ctnet)
- *
- * @return
- */
- public static boolean isCtcNetwork(Context context) {
- byte type = getCurrentNetType(context);
-
- return isCtcNetwork(type);
- }
-
- public static boolean isCtcNetwork(String apnName) {
- if (apnName == null) {
- return false;
- }
-
- if (apnName.equals(CONNECT_TYPE_CTWAP) || apnName.equals(CONNECT_TYPE_CTNET)) {
- return true;
- } else {
- return false;
- }
- }
-
- public static boolean isCtcNetwork(byte type) {
- if (type == CURRENT_NETWORK_TYPE_CTWAP || type == CURRENT_NETWORK_TYPE_CTNET) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * 判断是否是联通网络(uniwap,uninet,3gwap,3gnet)
- *
- * @return
- */
- public static boolean isCucNetwork(Context context) {
- byte type = getCurrentNetType(context);
-
- return isCucNetwork(type);
- }
-
- public static boolean isCucNetwork(String apnName) {
- if (apnName == null) {
- return false;
- }
-
- if (apnName.equals(CONNECT_TYPE_UNIWAP) || apnName.equals(CONNECT_TYPE_UNINET)
- || apnName.equals(CONNECT_TYPE_UNI3GWAP) || apnName.equals(CONNECT_TYPE_UNI3GNET)) {
- return true;
- } else {
- return false;
- }
- }
-
- public static boolean isCucNetwork(byte type) {
- if (type == CURRENT_NETWORK_TYPE_UNIWAP || type == CURRENT_NETWORK_TYPE_UNIET) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * 判断是否是移动网络(cmwap,cmnet)
- *
- * @return
- */
- public static boolean isCmbNetwork(Context context) {
- byte type = getCurrentNetType(context);
-
- return isCmbNetwork(type);
- }
-
- public static boolean isCmbNetwork(String apnName) {
- if (apnName == null) {
- return false;
- }
-
- if (apnName.equals(CONNECT_TYPE_CMWAP) || apnName.equals(CONNECT_TYPE_CMNET)) {
- return true;
- } else {
- return false;
- }
- }
-
- public static boolean isCmbNetwork(byte type) {
- if (type == CURRENT_NETWORK_TYPE_CMWAP || type == CURRENT_NETWORK_TYPE_CMNET) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * 获取网络运营商类型(中国移动,中国联通,中国电信,wifi)
- *
- * @param context
- * @return
- */
- public static byte getNetworkOperators(Context context) {
- if (isWifi(context)) {
- return CURRENT_NETWORK_TYPE_WIFI;
- } else if (isCtcNetwork(context)) {
- return CURRENT_NETWORK_TYPE_CTC;
- } else if (isCmbNetwork(context)) {
- return CURRENT_NETWORK_TYPE_CM;
- } else if (isCucNetwork(context)) {
- return CURRENT_NETWORK_TYPE_CUC;
- } else {
- return CURRENT_NETWORK_TYPE_NONE;
- }
- }
-
- public static byte getNetworkOperators(byte type) {
- if (type == CURRENT_NETWORK_TYPE_NONE) {
- return CURRENT_NETWORK_TYPE_NONE;
- } else if (type == CURRENT_NETWORK_TYPE_WIFI) {
- return CURRENT_NETWORK_TYPE_WIFI;
- } else if (type == CURRENT_NETWORK_TYPE_CTNET || type == CURRENT_NETWORK_TYPE_CTWAP) {
- return CURRENT_NETWORK_TYPE_CTC;
- } else if (type == CURRENT_NETWORK_TYPE_CMWAP || type == CURRENT_NETWORK_TYPE_CMNET) {
- return CURRENT_NETWORK_TYPE_CM;
- } else if (type == CURRENT_NETWORK_TYPE_UNIWAP || type == CURRENT_NETWORK_TYPE_UNIET) {
- return CURRENT_NETWORK_TYPE_CUC;
- } else {
- return CURRENT_NETWORK_TYPE_NONE;
- }
- }
-
- /**
- * 是否需要设置代理(网络请求,一般用于wap网络,但有些机型设置代理会导致系统异常)
- *
- * @return
- */
- public static boolean isNeedSetProxyForNetRequest() { // #00044 +
- if (Build.MODEL.equals("SCH-N719") || Build.MODEL.equals("SCH-I939D")) {
- return false;
- } else {
- return true;
- }
- }
-
- /**
- * get mac address of wifi if wifi is active
- */
-
- public static String getActiveMacAddress(Context context) {
- WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
-
- WifiInfo info = wifi.getConnectionInfo();
-
- if (info != null) {
- return info.getMacAddress();
- }
-
- return "";
- }
-
- public static String getNetworkInfo(Context context) {
- String info = "";
- ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- if (connectivity != null) {
- NetworkInfo activeNetInfo = connectivity.getActiveNetworkInfo();
- if (activeNetInfo != null) {
- if (activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
- info = activeNetInfo.getTypeName();
- } else {
- StringBuilder sb = new StringBuilder();
- TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- sb.append(activeNetInfo.getTypeName());
- sb.append(" [");
- if (tm != null) {
- // Result may be unreliable on CDMA networks
- sb.append(tm.getNetworkOperatorName());
- sb.append("#");
- }
- sb.append(activeNetInfo.getSubtypeName());
- sb.append("]");
- info = sb.toString();
- }
- }
- }
- return info;
- }
-
- public enum NetworkSpeedMode {
- LOW, NORMAL, HIGH, UNKNOWN
- }
-
- /**
- * 网络类型
- */
- public static final int NETWORK_CLASS_UNKNOWN = 0;
-
- public static final int NETWORK_CLASS_2_G = 1;
-
- public static final int NETWORK_CLASS_3_G = 2;
-
- public static final int NETWORK_CLASS_4_G = 3;
-
- public static final int NETWORK_CLASS_WIFI = 10;
-
- /**
- * 仅判断Mobile网络的慢速.蓝牙等其他网络不做判断.
- *
- * @param context
- * @return
- */
- public static NetworkSpeedMode getNetworkSpeedModeInMobile(Context context) {
- ConnectivityManager connectivityManager = (ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- if (connectivityManager != null) {
- NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
- if (networkInfo != null) {
- if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
- switch (networkInfo.getSubtype()) {
- case TelephonyManager.NETWORK_TYPE_IDEN: // ~25 kbps
- return NetworkSpeedMode.LOW;
- case TelephonyManager.NETWORK_TYPE_CDMA: // ~ 14-64 kbps
- return NetworkSpeedMode.LOW;
- case TelephonyManager.NETWORK_TYPE_1xRTT: // ~ 50-100 kbps
- return NetworkSpeedMode.LOW;
- case TelephonyManager.NETWORK_TYPE_EDGE: // ~ 50-100 kbps
- return NetworkSpeedMode.LOW;
- case TelephonyManager.NETWORK_TYPE_GPRS: // ~ 100 kbps
- return NetworkSpeedMode.LOW;
-
- case TelephonyManager.NETWORK_TYPE_EVDO_0: // ~ 400-1000
- // kbps
- return NetworkSpeedMode.NORMAL;
- case TelephonyManager.NETWORK_TYPE_EVDO_A: // ~ 600-1400
- // kbps
- return NetworkSpeedMode.NORMAL;
- case TelephonyManager.NETWORK_TYPE_HSPA: // ~ 700-1700 kbps
- return NetworkSpeedMode.NORMAL;
- case TelephonyManager.NETWORK_TYPE_UMTS: // ~ 400-7000 kbps
- return NetworkSpeedMode.NORMAL;
- case 14: // TelephonyManager.NETWORK_TYPE_EHRPD: // ~ 1-2
- // Mbps
- return NetworkSpeedMode.NORMAL;
- case 12: // TelephonyManager.NETWORK_TYPE_EVDO_B: // ~ 5
- // Mbps
- return NetworkSpeedMode.NORMAL;
-
- case TelephonyManager.NETWORK_TYPE_HSDPA: // ~ 2-14 Mbps
- return NetworkSpeedMode.HIGH;
- case TelephonyManager.NETWORK_TYPE_HSUPA: // ~ 1-23 Mbps
- return NetworkSpeedMode.HIGH;
- case 15: // TelephonyManager.NETWORK_TYPE_HSPAP: // ~ 10-20
- // Mbps
- return NetworkSpeedMode.HIGH;
- case 13: // TelephonyManager.NETWORK_TYPE_LTE: // ~ 10+ Mbps
- return NetworkSpeedMode.HIGH;
-
- case TelephonyManager.NETWORK_TYPE_UNKNOWN:
- return NetworkSpeedMode.NORMAL;
- default:
- break;
- }
- }
- }
- }
- return NetworkSpeedMode.UNKNOWN;
- }
-
- /**
- * 获取在Mobile网络下的网络类型. 2G,3G,4G
- *
- * @param context
- * @return
- */
- public static int getNetworkClass(Context context) {
- ConnectivityManager connectivityManager = (ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- if (connectivityManager != null) {
- NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
- if (networkInfo != null) {
- if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
- switch (networkInfo.getSubtype()) {
- case TelephonyManager.NETWORK_TYPE_GPRS:
- case TelephonyManager.NETWORK_TYPE_EDGE:
- case TelephonyManager.NETWORK_TYPE_CDMA:
- case TelephonyManager.NETWORK_TYPE_1xRTT:
- case TelephonyManager.NETWORK_TYPE_IDEN:
- return NETWORK_CLASS_2_G;
- case TelephonyManager.NETWORK_TYPE_UMTS:
- case TelephonyManager.NETWORK_TYPE_EVDO_0:
- case TelephonyManager.NETWORK_TYPE_EVDO_A:
- case TelephonyManager.NETWORK_TYPE_HSDPA:
- case TelephonyManager.NETWORK_TYPE_HSUPA:
- case TelephonyManager.NETWORK_TYPE_HSPA:
- case 12: // TelephonyManager.NETWORK_TYPE_EVDO_B:
- case 14: // TelephonyManager.NETWORK_TYPE_EHRPD:
- case 15: // TelephonyManager.NETWORK_TYPE_HSPAP:
- return NETWORK_CLASS_3_G;
- case 13: // TelephonyManager.NETWORK_TYPE_LTE:
- return NETWORK_CLASS_4_G;
- default:
- return NETWORK_CLASS_UNKNOWN;
- }
- } else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
- return NETWORK_CLASS_WIFI;
- }
- }
- }
- return NETWORK_CLASS_UNKNOWN;
- }
-
- public static String getNetworkTypeName(Context context) {
- String networkName = "UNKNOWN";
- ConnectivityManager connectivityManager = (ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- if (connectivityManager != null) {
- NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
- if (networkInfo != null) {
- networkName = getNetworkTypeName(networkInfo.getType());
- if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
- networkName += "#" + getNetworkTypeNameInMobile(networkInfo.getSubtype());
- }
- }
- }
- return networkName;
- }
-
- private static String getNetworkTypeNameInMobile(int type) {
- switch (type) {
- case TelephonyManager.NETWORK_TYPE_GPRS:
- return "GPRS";
- case TelephonyManager.NETWORK_TYPE_EDGE:
- return "EDGE";
- case TelephonyManager.NETWORK_TYPE_UMTS:
- return "UMTS";
- case TelephonyManager.NETWORK_TYPE_HSDPA:
- return "HSDPA";
- case TelephonyManager.NETWORK_TYPE_HSUPA:
- return "HSUPA";
- case TelephonyManager.NETWORK_TYPE_HSPA:
- return "HSPA";
- case TelephonyManager.NETWORK_TYPE_CDMA:
- return "CDMA";
- case TelephonyManager.NETWORK_TYPE_EVDO_0:
- return "CDMA - EvDo rev. 0";
- case TelephonyManager.NETWORK_TYPE_EVDO_A:
- return "CDMA - EvDo rev. A";
- case TelephonyManager.NETWORK_TYPE_EVDO_B:
- return "CDMA - EvDo rev. B";
- case TelephonyManager.NETWORK_TYPE_1xRTT:
- return "CDMA - 1xRTT";
- case TelephonyManager.NETWORK_TYPE_LTE:
- return "LTE";
- case TelephonyManager.NETWORK_TYPE_EHRPD:
- return "CDMA - eHRPD";
- case TelephonyManager.NETWORK_TYPE_IDEN:
- return "iDEN";
- case TelephonyManager.NETWORK_TYPE_HSPAP:
- return "HSPA+";
- default:
- return "UNKNOWN";
- }
- }
-
- private static String getNetworkTypeName(int type) {
- switch (type) {
- case ConnectivityManager.TYPE_MOBILE:
- return "MOBILE";
- case ConnectivityManager.TYPE_WIFI:
- return "WIFI";
- case ConnectivityManager.TYPE_MOBILE_MMS:
- return "MOBILE_MMS";
- case ConnectivityManager.TYPE_MOBILE_SUPL:
- return "MOBILE_SUPL";
- case ConnectivityManager.TYPE_MOBILE_DUN:
- return "MOBILE_DUN";
- case ConnectivityManager.TYPE_MOBILE_HIPRI:
- return "MOBILE_HIPRI";
- case ConnectivityManager.TYPE_WIMAX:
- return "WIMAX";
- case ConnectivityManager.TYPE_BLUETOOTH:
- return "BLUETOOTH";
- case ConnectivityManager.TYPE_DUMMY:
- return "DUMMY";
- case ConnectivityManager.TYPE_ETHERNET:
- return "ETHERNET";
- case 10: // ConnectivityManager.TYPE_MOBILE_FOTA:
- return "MOBILE_FOTA";
- case 11: // ConnectivityManager.TYPE_MOBILE_IMS:
- return "MOBILE_IMS";
- case 12: // ConnectivityManager.TYPE_MOBILE_CBS:
- return "MOBILE_CBS";
- case 13: // ConnectivityManager.TYPE_WIFI_P2P:
- return "WIFI_P2P";
- default:
- return Integer.toString(type);
- }
- }
-
- //中国电信
- public static final int ISP_CTCC = 0;
- //中国联通
- public static final int ISP_CUCC = 1;
- //中国移动
- public static final int ISP_CMCC = 2;
- //中国铁通
- public static final int ISP_CTT = 3;
- //其他
- public static final int ISP_OTHERS = -1;
-
- public static String getSimOperator(Context context) {
- TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- if (tm != null) {
- return tm.getSimOperator();
- }
- return null;
- }
-
- public static String getNetworkOperator(Context context) {
- TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- if (tm != null) {
- return tm.getNetworkOperator();
- }
- return null;
- }
-
-
- public interface LinkNetWorkType {
- public static final int UNKNOWN = 0;
- public static final int WIFI = 1;
- public static final int WWAN = 2;
- public static final int _2G = 3;
- public static final int _3G = 4;
- public static final int _4G = 5;
- }
-
- public static int getNetworkTypeForLink(Context context) {
- try {
- ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo ni = cm.getActiveNetworkInfo();
- if (ni != null) {
- if (ni.getType() == ConnectivityManager.TYPE_WIFI) {
- return LinkNetWorkType.WIFI;
- } else {
- if (ni.getType() == ConnectivityManager.TYPE_MOBILE) {
- switch (ni.getSubtype()) {
- case TelephonyManager.NETWORK_TYPE_GPRS:
- case TelephonyManager.NETWORK_TYPE_EDGE:
- case TelephonyManager.NETWORK_TYPE_CDMA:
- case TelephonyManager.NETWORK_TYPE_1xRTT:
- case TelephonyManager.NETWORK_TYPE_IDEN:
- return LinkNetWorkType._2G;
- case TelephonyManager.NETWORK_TYPE_UMTS:
- case TelephonyManager.NETWORK_TYPE_EVDO_0:
- case TelephonyManager.NETWORK_TYPE_EVDO_A:
- case TelephonyManager.NETWORK_TYPE_HSDPA:
- case TelephonyManager.NETWORK_TYPE_HSUPA:
- case TelephonyManager.NETWORK_TYPE_HSPA:
- case 12: // TelephonyManager.NETWORK_TYPE_EVDO_B:
- case 14: // TelephonyManager.NETWORK_TYPE_EHRPD:
- case 15: // TelephonyManager.NETWORK_TYPE_HSPAP:
- return LinkNetWorkType._3G;
- case 13: // TelephonyManager.NETWORK_TYPE_LTE:
- return LinkNetWorkType._4G;
- default:
- return LinkNetWorkType._2G;
- }
- }
- }
- }
- } catch (Exception e) {
- return LinkNetWorkType.UNKNOWN;
- }
- return LinkNetWorkType.UNKNOWN;
- }
}