31
31
public class UploadService extends IntentService {
32
32
33
33
private static final String SERVICE_NAME = UploadService .class .getName ();
34
- private static final String TAG = "AndroidUploadService" ;
34
+ private static final String TAG = "AndroidUploadService" ;
35
35
36
36
private static final int UPLOAD_NOTIFICATION_ID = 1234 ; // Something unique
37
37
private static final int UPLOAD_NOTIFICATION_ID_DONE = 1235 ; // Something unique
@@ -59,9 +59,9 @@ public class UploadService extends IntentService {
59
59
public static final String SERVER_RESPONSE_CODE = "serverResponseCode" ;
60
60
public static final String SERVER_RESPONSE_MESSAGE = "serverResponseMessage" ;
61
61
62
- private NotificationManager notificationManager ;
62
+ private NotificationManager notificationManager ;
63
63
private Builder notification ;
64
- private PowerManager .WakeLock wakeLock ;
64
+ private PowerManager .WakeLock wakeLock ;
65
65
private UploadNotificationConfig notificationConfig ;
66
66
private int lastPublishedProgress ;
67
67
@@ -104,7 +104,8 @@ public UploadService() {
104
104
@ Override
105
105
public void onCreate () {
106
106
super .onCreate ();
107
- notificationManager = (NotificationManager ) getSystemService (NOTIFICATION_SERVICE );
107
+
108
+ notificationManager = (NotificationManager ) getSystemService (NOTIFICATION_SERVICE );
108
109
notification = new NotificationCompat .Builder (this );
109
110
PowerManager pm = (PowerManager ) getSystemService (POWER_SERVICE );
110
111
wakeLock = pm .newWakeLock (PowerManager .PARTIAL_WAKE_LOCK , TAG );
@@ -117,7 +118,7 @@ protected void onHandleIntent(Intent intent) {
117
118
118
119
if (ACTION_UPLOAD .equals (action )) {
119
120
notificationConfig = intent .getParcelableExtra (PARAM_NOTIFICATION_CONFIG );
120
- final String uploadId = intent .getStringExtra (PARAM_ID );
121
+ final String uploadId = intent .getStringExtra (PARAM_ID );
121
122
final String url = intent .getStringExtra (PARAM_URL );
122
123
final String method = intent .getStringExtra (PARAM_METHOD );
123
124
final ArrayList <FileToUpload > files = intent .getParcelableArrayListExtra (PARAM_FILES );
@@ -132,15 +133,15 @@ protected void onHandleIntent(Intent intent) {
132
133
} catch (Exception exception ) {
133
134
broadcastError (uploadId , exception );
134
135
} finally {
135
- wakeLock .release ();
136
- }
136
+ wakeLock .release ();
137
+ }
137
138
}
138
139
}
139
140
}
140
141
141
142
private void handleFileUpload (final String uploadId ,
142
- final String url ,
143
- final String method ,
143
+ final String url ,
144
+ final String method ,
144
145
final ArrayList <FileToUpload > filesToUpload ,
145
146
final ArrayList <NameValue > requestHeaders ,
146
147
final ArrayList <NameValue > requestParameters )
@@ -210,7 +211,7 @@ private byte[] getTrailerBytes(final String boundary)
210
211
}
211
212
212
213
private HttpURLConnection getMultipartHttpURLConnection (final String url ,
213
- final String method ,
214
+ final String method ,
214
215
final String boundary )
215
216
throws IOException {
216
217
final HttpURLConnection conn = (HttpURLConnection ) new URL (url ).openConnection ();
@@ -384,25 +385,28 @@ private void updateNotificationProgress(final int progress) {
384
385
}
385
386
386
387
private void updateNotificationCompleted () {
387
- stopForeground (notificationConfig .isAutoClearOnSuccess ());
388
+ stopForeground (notificationConfig .isAutoClearOnSuccess ());
388
389
389
- if (!notificationConfig .isAutoClearOnSuccess ()) {
390
+ if (!notificationConfig .isAutoClearOnSuccess ()) {
390
391
notification .setContentTitle (notificationConfig .getTitle ())
391
392
.setContentText (notificationConfig .getCompleted ())
392
393
.setSmallIcon (notificationConfig .getIconResourceID ())
393
394
.setProgress (0 , 0 , false )
394
395
.setOngoing (false );
396
+
395
397
notificationManager .notify (UPLOAD_NOTIFICATION_ID_DONE , notification .build ());
396
398
}
397
399
}
398
400
399
401
private void updateNotificationError () {
400
- stopForeground (false );
402
+ stopForeground (false );
403
+
401
404
notification .setContentTitle (notificationConfig .getTitle ())
402
405
.setContentText (notificationConfig .getError ())
403
406
.setSmallIcon (notificationConfig .getIconResourceID ())
404
407
.setProgress (0 , 0 , false )
405
408
.setOngoing (false );
409
+
406
410
notificationManager .notify (UPLOAD_NOTIFICATION_ID_DONE , notification .build ());
407
411
}
408
412
}
0 commit comments