Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(LocalNotifications): Allow to create notifications without activity #2648

Merged
merged 2 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,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 @@ -246,7 +246,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