https://github.com/AriaLyy/Aria/issues/610 https://github.com/AriaLyy/Aria/issues/614
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user