Skip to content

Commit

Permalink
feat(LocalNotifications): Allow to create notifications without activ…
Browse files Browse the repository at this point in the history
…ity (#2648)
  • Loading branch information
dwlrathod authored Apr 3, 2020
1 parent d72e25d commit a4e5918
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public LocalNotifications() {
public void load() {
super.load();
notificationStorage = new NotificationStorage(getContext());
manager = new LocalNotificationManager(notificationStorage, getActivity());
manager = new LocalNotificationManager(notificationStorage, getActivity(), getContext());
manager.createNotificationChannel();
notificationChannelManager = new NotificationChannelManager(getActivity());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public class LocalNotificationManager {
private Activity activity;
private NotificationStorage storage;

public LocalNotificationManager(NotificationStorage notificationStorage, Activity activity) {
public LocalNotificationManager(NotificationStorage notificationStorage, Activity activity, Context context ) {
storage = notificationStorage;
this.activity = activity;
this.context = activity;
this.context = context;
}

/**
Expand Down Expand Up @@ -260,7 +260,13 @@ private void createActionIntents(LocalNotification localNotification, Notificati

@NonNull
private Intent buildIntent(LocalNotification localNotification, String action) {
Intent intent = new Intent(context, activity.getClass());
Intent intent;
if (activity != null) {
intent = new Intent(context, activity.getClass());
} else {
String packageName = context.getPackageName();
intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
}
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Expand Down

0 comments on commit a4e5918

Please sign in to comment.