文件下载:兼容各种机型
下载通知:兼容android各个系统
public class DownloadService extends Service {
private static final String TAG = "downApkTag" ;
public static final int DOWN_SUCCESS = 0x1001 ;
public static final int DOWN_LOADING = 0x1002 ;
public static final int DOWN_ERROR = 0x1003 ;
public static final int DOWN_START = 0x1004 ;
private NotificationManager notificationManager;
private Notification notification;
private NotificationCompat. Builder builder;
private String file_name;
public static final String KEY_DOWN_URL = "Down_Url" ;
public static final String KEY_FILE_NAME = "File_Name" ;
private static String down_url;
private final int NotificationID = 1 ;
private int percent = 0 ;
protected static final String CHANNEL_ID = "download_apk_notification" ;
private String downloadApkPath;
public static boolean isDownloading = false ;
@Nullable
@Override
public IBinder onBind ( Intent intent) {
return null;
}
@Override
public int onStartCommand ( Intent intent, int flags, int startId) {
if ( intent != null) {
file_name = intent. getStringExtra ( KEY_FILE_NAME) ;
down_url = intent. getStringExtra ( KEY_DOWN_URL) ;
}
LogUtil. d ( TAG, "KEY_FILE_NAME = " + file_name) ;
LogUtil. d ( TAG, "KEY_DOWN_URL = " + down_url) ;
String path = SdUtils. getDownloadPath ( ) ;
File file = new File ( path) ;
if ( ! file. exists ( ) ) {
file. mkdirs ( ) ;
}
downloadApkPath = path + file_name;
LogUtil. d ( TAG