Merge pull request #79 from lbryio/service-notification

Removed service foreground notification
This commit is contained in:
akinwale 2018-04-24 15:59:20 +01:00 committed by GitHub
commit 77a86da984
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View file

@ -34,6 +34,11 @@ public class LbrynetService extends PythonService {
public static LbrynetService serviceInstance;
@Override
public boolean canDisplayNotification() {
return false;
}
@Override
public int startType() {
return START_STICKY;

View file

@ -11,6 +11,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import io.lbry.browser.MainActivity;
import io.lbry.browser.R;
import io.lbry.browser.receivers.NotificationDeletedReceiver;
@ -19,6 +20,7 @@ import java.util.HashMap;
import java.util.Random;
public class DownloadManagerModule extends ReactContextBaseJavaModule {
private Context context;
private HashMap<Integer, NotificationCompat.Builder> builders = new HashMap<Integer, NotificationCompat.Builder>();
@ -71,6 +73,13 @@ public class DownloadManagerModule extends ReactContextBaseJavaModule {
groupCreated = true;
}
}
private PendingIntent getLaunchPendingIntent() {
Intent launchIntent = new Intent(context, MainActivity.class);
launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, launchIntent, 0);
return intent;
}
@ReactMethod
public void startDownload(String id, String fileName) {
@ -78,12 +87,12 @@ public class DownloadManagerModule extends ReactContextBaseJavaModule {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(String.format("Downloading %s...", fileName))
.setSmallIcon(R.drawable.ic_file_download_black_24dp)
builder.setContentIntent(getLaunchPendingIntent())
.setContentTitle(String.format("Downloading %s...", fileName))
.setGroup(GROUP_DOWNLOADS)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setGroup(GROUP_DOWNLOADS);
builder.setProgress(MAX_PROGRESS, 0, false);
.setProgress(MAX_PROGRESS, 0, false)
.setSmallIcon(R.drawable.ic_file_download_black_24dp);
int notificationId = generateNotificationId();
downloadIdNotificationIdMap.put(id, notificationId);
@ -106,9 +115,10 @@ public class DownloadManagerModule extends ReactContextBaseJavaModule {
createNotificationGroup();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
NotificationCompat.Builder builder = builders.get(notificationId);
builder.setProgress(MAX_PROGRESS, new Double(progress).intValue(), false);
builder.setContentText(String.format("%.0f%% (%s / %s)", progress, formatBytes(writtenBytes), formatBytes(totalBytes)));
builder.setGroup(GROUP_DOWNLOADS);
builder.setContentIntent(getLaunchPendingIntent())
.setContentText(String.format("%.0f%% (%s / %s)", progress, formatBytes(writtenBytes), formatBytes(totalBytes)))
.setGroup(GROUP_DOWNLOADS)
.setProgress(MAX_PROGRESS, new Double(progress).intValue(), false);
notificationManager.notify(notificationId, builder.build());
if (progress == MAX_PROGRESS) {