Removed service foreground notification. Tapping on the download progress notification should open the app.
This commit is contained in:
parent
496ec53f8a
commit
d018e9b577
2 changed files with 23 additions and 8 deletions
|
@ -34,6 +34,11 @@ public class LbrynetService extends PythonService {
|
||||||
|
|
||||||
public static LbrynetService serviceInstance;
|
public static LbrynetService serviceInstance;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canDisplayNotification() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int startType() {
|
public int startType() {
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
import com.facebook.react.bridge.ReactMethod;
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
|
|
||||||
|
import io.lbry.browser.MainActivity;
|
||||||
import io.lbry.browser.R;
|
import io.lbry.browser.R;
|
||||||
import io.lbry.browser.receivers.NotificationDeletedReceiver;
|
import io.lbry.browser.receivers.NotificationDeletedReceiver;
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ import java.util.HashMap;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class DownloadManagerModule extends ReactContextBaseJavaModule {
|
public class DownloadManagerModule extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
private HashMap<Integer, NotificationCompat.Builder> builders = new HashMap<Integer, NotificationCompat.Builder>();
|
private HashMap<Integer, NotificationCompat.Builder> builders = new HashMap<Integer, NotificationCompat.Builder>();
|
||||||
|
@ -71,6 +73,13 @@ public class DownloadManagerModule extends ReactContextBaseJavaModule {
|
||||||
groupCreated = true;
|
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
|
@ReactMethod
|
||||||
public void startDownload(String id, String fileName) {
|
public void startDownload(String id, String fileName) {
|
||||||
|
@ -78,12 +87,12 @@ public class DownloadManagerModule extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||||
builder.setContentTitle(String.format("Downloading %s...", fileName))
|
builder.setContentIntent(getLaunchPendingIntent())
|
||||||
.setSmallIcon(R.drawable.ic_file_download_black_24dp)
|
.setContentTitle(String.format("Downloading %s...", fileName))
|
||||||
|
.setGroup(GROUP_DOWNLOADS)
|
||||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||||
.setGroup(GROUP_DOWNLOADS);
|
.setProgress(MAX_PROGRESS, 0, false)
|
||||||
|
.setSmallIcon(R.drawable.ic_file_download_black_24dp);
|
||||||
builder.setProgress(MAX_PROGRESS, 0, false);
|
|
||||||
|
|
||||||
int notificationId = generateNotificationId();
|
int notificationId = generateNotificationId();
|
||||||
downloadIdNotificationIdMap.put(id, notificationId);
|
downloadIdNotificationIdMap.put(id, notificationId);
|
||||||
|
@ -106,9 +115,10 @@ public class DownloadManagerModule extends ReactContextBaseJavaModule {
|
||||||
createNotificationGroup();
|
createNotificationGroup();
|
||||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||||
NotificationCompat.Builder builder = builders.get(notificationId);
|
NotificationCompat.Builder builder = builders.get(notificationId);
|
||||||
builder.setProgress(MAX_PROGRESS, new Double(progress).intValue(), false);
|
builder.setContentIntent(getLaunchPendingIntent())
|
||||||
builder.setContentText(String.format("%.0f%% (%s / %s)", progress, formatBytes(writtenBytes), formatBytes(totalBytes)));
|
.setContentText(String.format("%.0f%% (%s / %s)", progress, formatBytes(writtenBytes), formatBytes(totalBytes)))
|
||||||
builder.setGroup(GROUP_DOWNLOADS);
|
.setGroup(GROUP_DOWNLOADS)
|
||||||
|
.setProgress(MAX_PROGRESS, new Double(progress).intValue(), false);
|
||||||
notificationManager.notify(notificationId, builder.build());
|
notificationManager.notify(notificationId, builder.build());
|
||||||
|
|
||||||
if (progress == MAX_PROGRESS) {
|
if (progress == MAX_PROGRESS) {
|
||||||
|
|
Loading…
Reference in a new issue