Skip to content

Commit

Permalink
Update CocosDownloader.java
Browse files Browse the repository at this point in the history
解决 GlobalObject.getContext() 为 null 时,  下载任务出错的bug.
  • Loading branch information
finscn authored Nov 23, 2024
1 parent 667005f commit c0607c4
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ public void run() {

host = domain.startsWith("www.") ? domain.substring(4) : domain;
if (fileLen > 0) {
SharedPreferences sharedPreferences = GlobalObject.getContext().getSharedPreferences("breakpointDownloadSupport", Context.MODE_PRIVATE);
Context context = GlobalObject.getContext();
if (context == null) {
return;
}
SharedPreferences sharedPreferences = context.getSharedPreferences("breakpointDownloadSupport", Context.MODE_PRIVATE);
if (sharedPreferences.contains(host) && sharedPreferences.getBoolean(host, false)) {
downloadStart = fileLen;
} else {
Expand Down Expand Up @@ -246,6 +250,9 @@ public void onResponse(Call call, Response response) throws IOException {

// save breakpointDownloadSupport Data to SharedPreferences storage
Context context = GlobalObject.getContext();
if (context == null) {
return;
}
SharedPreferences sharedPreferences = context.getSharedPreferences("breakpointDownloadSupport", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
long total = response.body().contentLength() + downloadStart;
Expand Down

0 comments on commit c0607c4

Please sign in to comment.