Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
17 changes: 15 additions & 2 deletions src/android/UploadNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import androidx.annotation.IntegerRes;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import androidx.work.ForegroundInfo;
import androidx.work.WorkInfo;
import androidx.work.WorkManager;
import android.content.pm.ServiceInfo;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -82,7 +84,7 @@ public static Notification createNotification(NotificationCompat.Builder notific
Notification notification = notificationBuilder.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
return notification;
return notification;
}

@RequiresApi(api = Build.VERSION_CODES.O)
Expand All @@ -103,7 +105,9 @@ private static NotificationCompat.Builder getUploadNotification(final Context co
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, pendingIntentFlag);

// TODO: click intent open app
@SuppressLint("ResourceType") NotificationCompat.Builder uploadNotificationBuilder = new NotificationCompat.Builder(context, UploadTask.NOTIFICATION_CHANNEL_ID)
@SuppressLint("ResourceType")
NotificationCompat.Builder uploadNotificationBuilder = new NotificationCompat.Builder(context,
UploadTask.NOTIFICATION_CHANNEL_ID)
.setContentTitle(notificationTitle)
.setTicker(notificationTitle)
.setSmallIcon(notificationIconRes)
Expand All @@ -117,4 +121,13 @@ private static NotificationCompat.Builder getUploadNotification(final Context co

return uploadNotificationBuilder;
}

public ForegroundInfo getForegroundInfo() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
return new ForegroundInfo(notificationId, notificationBuilder.build(),
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
}

return new ForegroundInfo(notificationId, notificationBuilder.build());
}
}
15 changes: 13 additions & 2 deletions src/android/UploadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.webkit.MimeTypeMap;

import androidx.annotation.NonNull;
import androidx.work.ForegroundInfo;
import androidx.work.Data;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
Expand Down Expand Up @@ -155,7 +156,7 @@ public UploadTask(@NonNull Context context, @NonNull WorkerParameters workerPara
@NonNull
@Override
public Result doWork() {
if(!hasNetworkConnection()) {
if (!hasNetworkConnection()) {
return Result.retry();
}

Expand Down Expand Up @@ -395,12 +396,22 @@ private void handleNotification() {
Log.d(TAG, "Upload Notification");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
setForegroundAsync(uploadForegroundNotification.getForegroundInfo(getApplicationContext()));
} else {
} else {
uploadNotification.updateProgress();
}
Log.d(TAG, "Upload Notification Exit");
}

@NonNull
@Override
public ForegroundInfo getForegroundInfo() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
return uploadForegroundNotification.getForegroundInfo(getApplicationContext());
}

return uploadNotification.getForegroundInfo();
}

private synchronized boolean hasNetworkConnection() {
ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
if((connectivityManager == null) || (connectivityManager.getActiveNetworkInfo() == null) || (connectivityManager.getActiveNetworkInfo().isConnectedOrConnecting() == false)) {
Expand Down
Loading