14
14
import javax .net .ssl .HttpsURLConnection ;
15
15
import javax .net .ssl .SSLSession ;
16
16
17
+ import android .os .PowerManager ;
17
18
import android .app .IntentService ;
18
19
import android .content .Intent ;
19
20
import android .support .v4 .app .NotificationCompat ;
29
30
public class UploadService extends IntentService {
30
31
31
32
private static final String SERVICE_NAME = UploadService .class .getName ();
33
+ private static final String TAG = "AndroidUploadService" ;
32
34
33
35
private static final int UPLOAD_NOTIFICATION_ID = 1234 ; // Something unique
34
36
private static final int BUFFER_SIZE = 4096 ;
@@ -55,6 +57,7 @@ public class UploadService extends IntentService {
55
57
public static final String SERVER_RESPONSE_MESSAGE = "serverResponseMessage" ;
56
58
57
59
private Builder notification ;
60
+ private PowerManager .WakeLock wakeLock ;
58
61
private UploadNotificationConfig notificationConfig ;
59
62
private int lastPublishedProgress ;
60
63
@@ -97,6 +100,8 @@ public void onCreate() {
97
100
super .onCreate ();
98
101
notification = new NotificationCompat .Builder (this )
99
102
.setOngoing (true );
103
+ PowerManager pm = (PowerManager ) getSystemService (POWER_SERVICE );
104
+ wakeLock = pm .newWakeLock (PowerManager .PARTIAL_WAKE_LOCK , TAG );
100
105
}
101
106
102
107
@ Override
@@ -113,12 +118,15 @@ protected void onHandleIntent(Intent intent) {
113
118
final ArrayList <NameValue > parameters = intent .getParcelableArrayListExtra (PARAM_REQUEST_PARAMETERS );
114
119
115
120
lastPublishedProgress = 0 ;
121
+ wakeLock .acquire ();
116
122
try {
117
123
createNotification ();
118
124
handleFileUpload (uploadId , url , files , headers , parameters );
119
125
} catch (Exception exception ) {
120
126
broadcastError (uploadId , exception );
121
- }
127
+ } finally {
128
+ wakeLock .release ();
129
+ }
122
130
}
123
131
}
124
132
}
0 commit comments