Java Code Examples for androidx.core.app.NotificationManagerCompat#cancel()

The following examples show how to use androidx.core.app.NotificationManagerCompat#cancel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Event.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
private void removeStartEventNotificationAlarm(DataWrapper dataWrapper) {
    if (_repeatNotificationStart) {
        /*boolean clearNotification = true;
        for (int i = eventTimelineList.size()-1; i > 0; i--)
        {
            EventTimeline _eventTimeline = eventTimelineList.get(i);
            Event event = dataWrapper.getEventById(_eventTimeline._fkEvent);
            if ((event != null) && (event._repeatNotificationStart) && (event._id != this._id)) {
                // not clear, notification is from another event
                clearNotification = false;
                break;
            }
        }
        if (clearNotification) {*/
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(dataWrapper.context);
            try {
                notificationManager.cancel(
                        PPApplication.NOTIFY_EVENT_START_NOTIFICATION_TAG+"_"+_id,
                        PPApplication.NOTIFY_EVENT_START_NOTIFICATION_ID + (int) _id);
            } catch (Exception e) {
                PPApplication.recordException(e);
            }
            StartEventNotificationBroadcastReceiver.removeAlarm(this, dataWrapper.context);
        //}
    }
}
 
Example 2
Source File: MainActivity.java    From abnd-track-pomodoro-timer-app with MIT License 6 votes vote down vote up
/**
 * Displays a notification when foreground service is finished.
 */
private void displayTaskInformationNotification() {
    Notification notification = createTaskInformationNotification().build();
    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat
            .from(this);

    // Clearing any previous notifications.
    notificationManagerCompat
            .cancel(TASK_INFORMATION_NOTIFICATION_ID);

    // Displays a notification.
    if (!isServiceRunning(CountDownTimerService.class)) {
        notificationManagerCompat
                .notify(TASK_INFORMATION_NOTIFICATION_ID, notification);
    }
}
 
Example 3
Source File: NotificationCenter.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
public void removeNotifications(int chatId) {
    boolean removeSummary = false;
    synchronized (inboxes) {
        inboxes.remove(chatId);
        removeSummary = inboxes.isEmpty();
    }

    try {
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
        notificationManager.cancel(ID_MSG_OFFSET + chatId);
        if (removeSummary) {
            notificationManager.cancel(ID_MSG_SUMMARY);
        }
    } catch (Exception e) { Log.w(TAG, e); }
}
 
Example 4
Source File: BigTextIntentService.java    From android-Notifications with Apache License 2.0 5 votes vote down vote up
/**
 * Handles action Dismiss in the provided background thread.
 */
private void handleActionDismiss() {
    Log.d(TAG, "handleActionDismiss()");

    NotificationManagerCompat notificationManagerCompat =
            NotificationManagerCompat.from(getApplicationContext());
    notificationManagerCompat.cancel(MainActivity.NOTIFICATION_ID);
}
 
Example 5
Source File: BigTextIntentService.java    From android-Notifications with Apache License 2.0 5 votes vote down vote up
/**
 * Handles action Dismiss in the provided background thread.
 */
private void handleActionDismiss() {
    Log.d(TAG, "handleActionDismiss()");

    NotificationManagerCompat notificationManagerCompat =
            NotificationManagerCompat.from(getApplicationContext());
    notificationManagerCompat.cancel(StandaloneMainActivity.NOTIFICATION_ID);
}
 
Example 6
Source File: NotificationHelper.java    From MaxLock with GNU General Public License v3.0 5 votes vote down vote up
public static void postIModNotification(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        createNotificationChannels(context);
    }

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    if (!MLPreferences.getPrefsApps(context).getBoolean(Common.SHOW_RESET_RELOCK_TIMER_NOTIFICATION, false)) {
        nm.cancel(IMOD_NOTIFICATION_ID);
        return;
    }
    Intent notifyIntent = new Intent(context, ActionActivity.class);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    notifyIntent.putExtra(ActionsHelper.ACTION_EXTRA_KEY, ActionsHelper.ACTION_IMOD_RESET);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, IMOD_CHANNEL)
            .setContentTitle(context.getString(R.string.action_imod_reset))
            .setContentText("")
            .setSmallIcon(R.drawable.ic_apps_24dp)
            .setContentIntent(PendingIntent.getActivity(context.getApplicationContext(), 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT))
            .setOngoing(true)
            .setAutoCancel(true)
            .setShowWhen(false)
            .setPriority(NotificationCompat.PRIORITY_MIN)
            .setCategory(NotificationCompat.CATEGORY_STATUS)
            .setColor(ContextCompat.getColor(context, R.color.accent));
    nm.notify(IMOD_NOTIFICATION_ID, builder.build());
}
 
Example 7
Source File: ChannelNotificationManager.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onMessageSent() {
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(mContext);
    notificationManager.cancel(mNotificationId);

    NotificationManager.getInstance().onNotificationDismissed(mContext, mConnection,
            mChannel);
    NotificationManager.getInstance().updateSummaryNotification(mContext, null);
}
 
Example 8
Source File: IgnoreBatteryOptimizationNotification.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
static void removeNotification(Context context)
{
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    try {
        notificationManager.cancel(
                PPApplication.IGNORE_BATTERY_OPTIMIZATION_NOTIFICATION_TAG,
                PPApplication.IGNORE_BATTERY_OPTIMIZATION_NOTIFICATION_ID);
    } catch (Exception e) {
        PPApplication.recordException(e);
    }
}
 
Example 9
Source File: NotificationBroadcastReceiver.java    From NaviBee with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (REPLY_ACTION.equals(intent.getAction())) {
        CharSequence message = MyFirebaseMessagingService.getReplyMessage(intent);
        String convId = intent.getStringExtra(KEY_CONV_ID);
        int notiId = intent.getIntExtra(KEY_NOTI_ID, 0);
        sendMessageByConvId(convId, "text", message);

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(NaviBeeApplication.getInstance());
        notificationManager.cancel(notiId);
        MyFirebaseMessagingService.messages.remove(notiId);
    }
}
 
Example 10
Source File: ListenerService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private void showBolusProgress(int progresspercent, String progresstatus) {
    Intent cancelIntent = new Intent(this, ListenerService.class);
    cancelIntent.setAction(ACTION_CANCELBOLUS);
    PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0);

    long[] vibratePattern;
    boolean vibreate = PreferenceManager
            .getDefaultSharedPreferences(this).getBoolean("vibrateOnBolus", true);
    if(vibreate){
        vibratePattern = new long[]{0, 50, 1000};
    } else {
        vibratePattern = new long[]{0, 1, 1000};
    }

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_icon)
                    .setContentTitle("Bolus Progress")
                    .setContentText(progresspercent + "% - " + progresstatus)
                    .setContentIntent(cancelPendingIntent)
                    .setPriority(NotificationCompat.PRIORITY_MAX)
                    .setVibrate(vibratePattern)
                    .addAction(R.drawable.ic_cancel, "CANCEL BOLUS", cancelPendingIntent);

    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(this);

    if(confirmThread != null){
        confirmThread.invalidate();
    }
    notificationManager.notify(BOLUS_PROGRESS_NOTIF_ID, notificationBuilder.build());
    notificationManager.cancel(CONFIRM_NOTIF_ID); // multiple watch setup


    if (progresspercent == 100){
        scheduleDismissBolusprogress(5);
    }
}
 
Example 11
Source File: ImportantInfoNotification.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
static void removeNotification(Context context)
{
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    try {
        notificationManager.cancel(
                PPApplication.IMPORTANT_INFO_NOTIFICATION_TAG,
                PPApplication.IMPORTANT_INFO_NOTIFICATION_ID);
    } catch (Exception e) {
        PPApplication.recordException(e);
    }
}
 
Example 12
Source File: BigTextIntentService.java    From user-interface-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Handles action Dismiss in the provided background thread.
 */
private void handleActionDismiss() {
    Log.d(TAG, "handleActionDismiss()");

    NotificationManagerCompat notificationManagerCompat =
            NotificationManagerCompat.from(getApplicationContext());
    notificationManagerCompat.cancel(MainActivity.NOTIFICATION_ID);
}
 
Example 13
Source File: BigTextIntentService.java    From user-interface-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Handles action Dismiss in the provided background thread.
 */
private void handleActionDismiss() {
    Log.d(TAG, "handleActionDismiss()");

    NotificationManagerCompat notificationManagerCompat =
            NotificationManagerCompat.from(getApplicationContext());
    notificationManagerCompat.cancel(StandaloneMainActivity.NOTIFICATION_ID);
}
 
Example 14
Source File: ReservedValuesWorker.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void cancelNotification() {
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(getApplicationContext());
    notificationManager.cancel(SYNC_RV_ID);
}
 
Example 15
Source File: SyncDataWorker.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void cancelNotification() {
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(getApplicationContext());
    notificationManager.cancel(SYNC_DATA_ID);
}
 
Example 16
Source File: RefreshScheduler.java    From mimi-reader with Apache License 2.0 4 votes vote down vote up
private void hideNotification(Context context) {
    NotificationManagerCompat manager = NotificationManagerCompat.from(context);
    manager.cancel(RefreshJobService.NOTIFICATION_ID);
}
 
Example 17
Source File: MobiComConversationFragment.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if (MobiComUserPreference.getInstance(getActivity()).isChannelDeleted()) {
        MobiComUserPreference.getInstance(getActivity()).setDeleteChannel(false);
        if (getActivity().getSupportFragmentManager() != null) {
            getActivity().getSupportFragmentManager().popBackStack();
        }
        return;
    }

    ((ConversationActivity) getActivity()).setChildFragmentLayoutBGToTransparent();
    if (contact != null || channel != null) {
        BroadcastService.currentUserId = contact != null ? contact.getContactIds() : String.valueOf(channel.getKey());
        BroadcastService.currentConversationId = currentConversationId;
        if (BroadcastService.currentUserId != null) {
            NotificationManagerCompat nMgr = NotificationManagerCompat.from(getActivity());
            if (ApplozicClient.getInstance(getActivity()).isNotificationStacking()) {
                nMgr.cancel(NotificationService.NOTIFICATION_ID);
            } else {
                if (contact != null && !TextUtils.isEmpty(contact.getContactIds())) {
                    nMgr.cancel(contact.getContactIds().hashCode());
                }
                if (channel != null) {
                    nMgr.cancel(String.valueOf(channel.getKey()).hashCode());
                }
            }
        }

        if (downloadConversation != null) {
            downloadConversation.cancel(true);
        }

        if (channel != null) {
            Channel newChannel = ChannelService.getInstance(getActivity()).getChannelByChannelKey(channel.getKey());

            if (newChannel != null && newChannel.getType() != null && Channel.GroupType.OPEN.getValue().equals(newChannel.getType())) {
                MobiComUserPreference.getInstance(getActivity()).setNewMessageFlag(true);
            }

            enableOrDisableChannel(newChannel);

            if (ChannelService.isUpdateTitle) {
                updateChannelSubTitle(newChannel);
                ChannelService.isUpdateTitle = false;
            }
        }

        if (messageList.isEmpty()) {
            loadConversation(contact, channel, currentConversationId, null);
        } else if (MobiComUserPreference.getInstance(getContext()).getNewMessageFlag()) {
            MobiComUserPreference.getInstance(getContext()).setNewMessageFlag(false);
            loadNewMessageOnResume(contact, channel, currentConversationId);
        } else {
            Applozic.subscribeToTyping(getContext(), channel, contact);
        }

        if (SyncCallService.refreshView) {
            SyncCallService.refreshView = false;
        }

    }
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        public void onRefresh() {
            downloadConversation = new DownloadConversation(recyclerView, false, 1, 1, 1, contact, channel, currentConversationId);
            downloadConversation.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    });

}
 
Example 18
Source File: EditorEventListFragment.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
private void deleteEvent(final Event event)
{
    if (activityDataWrapper.getEventById(event._id) == null)
        // event not exists
        return;

    PPApplication.addActivityLog(activityDataWrapper.context, PPApplication.ALTYPE_EVENT_DELETED, event._name, null, null, 0, "");

    //listView.getRecycledViewPool().clear();

    synchronized (activityDataWrapper.eventList) {
        // remove notifications about event parameters errors
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(activityDataWrapper.context);
        try {
            notificationManager.cancel(
                    PPApplication.DISPLAY_PREFERENCES_EVENT_ERROR_NOTIFICATION_TAG+"_"+event._id,
                    PPApplication.EVENT_ID_NOTIFICATION_ID + (int) event._id);
        } catch (Exception e) {
            PPApplication.recordException(e);
        }
    }

    eventListAdapter.deleteItemNoNotify(event);
    DatabaseHandler.getInstance(activityDataWrapper.context).deleteEvent(event);

    // restart events
    //PPApplication.logE("$$$ restartEvents", "from EditorEventListFragment.deleteEvent");
    //activityDataWrapper.restartEvents(false, true, true, true, true);
    //PPApplication.logE("*********** restartEvents", "from EditorEventListFragment.deleteEvent()");
    activityDataWrapper.restartEventsWithRescan(true, false, true, false, true, false);

    eventListAdapter.notifyDataSetChanged();

    /*Intent serviceIntent = new Intent(getActivity().getApplicationContext(), PhoneProfilesService.class);
    serviceIntent.putExtra(PhoneProfilesService.EXTRA_ONLY_START, false);
    serviceIntent.putExtra(PhoneProfilesService.EXTRA_REREGISTER_RECEIVERS_AND_WORKERS, true);
    PPApplication.startPPService(getActivity(), serviceIntent);*/
    Intent commandIntent = new Intent(PhoneProfilesService.ACTION_COMMAND);
    //commandIntent.putExtra(PhoneProfilesService.EXTRA_ONLY_START, false);
    commandIntent.putExtra(PhoneProfilesService.EXTRA_REREGISTER_RECEIVERS_AND_WORKERS, true);
    PPApplication.runCommand(getActivity(), commandIntent);

    onStartEventPreferencesCallback.onStartEventPreferences(null, EDIT_MODE_DELETE, 0);
}
 
Example 19
Source File: SocketService.java    From zephyr with MIT License 4 votes vote down vote up
private void dismissServiceNotification() {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.cancel(ZephyrNotificationId.SOCKET_SERVICE_STATUS);
}
 
Example 20
Source File: NotificationManager.java    From Hentoid with Apache License 2.0 4 votes vote down vote up
public void cancel() {
    NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context);
    managerCompat.cancel(notificationId);
}