AndroidManifest.xml文件,权限申请部分
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
build.gradle内的dependencies里添加依赖
implementation 'com.squareup.okhttp3:okhttp:3.14.1'
同时在android内添加
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
DownloadService.java部分,使通知适配8.0
private Notification getNotification(String title, int progress) {
String channelId = "1";
String channelName = "Mychannel";
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(