laoyuyu
2020-02-17 23:49:13 +08:00
parent e015c2a2f7
commit 2f2d783655
8 changed files with 45 additions and 25 deletions

View File

@@ -21,6 +21,7 @@ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.os.Build;
import android.os.Handler;
@@ -120,6 +121,7 @@ public class AriaConfig {
* 注册网络监听,只有配置了检查网络{@link AppConfig#isNetCheck()}才会注册事件
*/
private void regNetCallBack(Context context) {
isConnectedNet = isNetworkAvailable();
if (!getAConfig().isNetCheck()) {
return;
}
@@ -155,6 +157,31 @@ public class AriaConfig {
}
}
public boolean isNetworkAvailable() {
// 获取手机所有连接管理对象包括对wi-fi,net等连接的管理
ConnectivityManager connectivityManager =
(ConnectivityManager) getAPP().getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager == null) {
return false;
} else {
// 获取NetworkInfo对象
NetworkInfo[] networkInfo = connectivityManager.getAllNetworkInfo();
if (networkInfo != null && networkInfo.length > 0) {
for (NetworkInfo info : networkInfo) {
// 判断当前网络状态是否为连接状态
if (info.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
public boolean isConnectedNet() {
return isConnectedNet;
}

View File

@@ -80,21 +80,21 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
@Override public int getTaskType() {
int type;
if (TextUtils.isEmpty(getUrl())) {
if (getUrl() == null){
type = ITaskWrapper.ERROR;
} else if (getUrl().startsWith("http")) {
type = ITaskWrapper.D_HTTP;
} else if (getUrl().startsWith("ftp")) {
type = ITaskWrapper.D_FTP;
} else if (getUrl().startsWith("sftp")) {
type = ITaskWrapper.D_SFTP;
} else {
M3U8Entity temp = getM3U8Entity();
if (temp == null) {
type = ITaskWrapper.D_HTTP;
} else {
type = temp.isLive() ? ITaskWrapper.M3U8_LIVE : ITaskWrapper.M3U8_VOD;
}
} else if (getUrl().startsWith("ftp")) {
type = ITaskWrapper.D_FTP;
} else if (getUrl().startsWith("sftp")) {
type = ITaskWrapper.D_SFTP;
} else {
type = ITaskWrapper.ERROR;
}
return type;
}