Java Code Examples for android.app.NotificationManager#cancelAll()

The following examples show how to use android.app.NotificationManager#cancelAll() . 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: MessageNotifier.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
private static void cancelActiveNotifications(@NonNull Context context) {
  NotificationManager notifications = ServiceUtil.getNotificationManager(context);
  notifications.cancel(SUMMARY_NOTIFICATION_ID);

  if (Build.VERSION.SDK_INT >= 23) {
    try {
      StatusBarNotification[] activeNotifications = notifications.getActiveNotifications();

      for (StatusBarNotification activeNotification : activeNotifications) {
        notifications.cancel(activeNotification.getId());
      }
    } catch (Throwable e) {
      // XXX Appears to be a ROM bug, see https://github.com/WhisperSystems/Signal-Android/issues/6043
      Log.w(TAG, e);
      notifications.cancelAll();
    }
  }
}
 
Example 2
Source File: CloseApplication.java    From QuranAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public void onTaskRemoved(Intent rootIntent) {
        AppPreference.setSelectionVerse(null);
//        //delete all selection in the image
//        Intent resetImage = new Intent(AppConstants.Highlight.RESET_IMAGE);
//        resetImage.putExtra(AppConstants.Highlight.RESET , true);
//        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(resetImage);
////        Toast.makeText(this, "Service Destroyeddddddd", Toast.LENGTH_LONG).show();
//        QuranPageFragment.SELECTION = false;
//        HighlightImageView.selectionFromTouch = false;
////        super.onTaskRemoved(rootIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancelAll();
//        Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
//        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//        intent.putExtra("EXIT", true);
//        startActivity(intent);
//        quit();
        trimCache();
        deleteCache(getApplicationContext());


    }
 
Example 3
Source File: SdlRouterService.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void exitForeground(){
	synchronized (NOTIFICATION_LOCK) {
		if (isForeground && !isPrimaryTransportConnected()) {	//Ensure that the service is in the foreground and no longer connected to a transport
			DebugTool.logInfo("SdlRouterService to exit foreground");
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
				this.stopForeground(Service.STOP_FOREGROUND_DETACH);
			}else{
				stopForeground(false);
			}
			NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
			if (notificationManager!= null){
				try {
					notificationManager.cancelAll();
					if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !getBooleanPref(KEY_AVOID_NOTIFICATION_CHANNEL_DELETE,false)) {
						notificationManager.deleteNotificationChannel(SDL_NOTIFICATION_CHANNEL_ID);
					}
				} catch (Exception e) {
					DebugTool.logError("Issue when removing notification and channel", e);
				}
			}
			isForeground = false;
		}
	}
}
 
Example 4
Source File: KlyphSession.java    From Klyph with MIT License 5 votes vote down vote up
public static void logout()
{		
	BaseApplication.getInstance().onLogout();
	
	NotificationManager nm = (NotificationManager) BaseApplication.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
	nm.cancelAll();
	
	setSessionUser(null);
	Session.getActiveSession().closeAndClearTokenInformation();
}
 
Example 5
Source File: SettingsActivity.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
    boolean isEnabled = (boolean) o;
    AppPreference.setNotificationEnabled(getActivity(), isEnabled);
    Intent intentToStartUpdate = new Intent("org.thosp.yourlocalweather.action.RESTART_NOTIFICATION_ALARM_SERVICE");
    intentToStartUpdate.setPackage("org.thosp.yourlocalweather");
    getActivity().startService(intentToStartUpdate);
    updateSummaries(isEnabled);
    NotificationManager notificationManager =
        (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
    return true;
}
 
Example 6
Source File: MainActivity.java    From BmapLite with GNU General Public License v3.0 5 votes vote down vote up
private void exitApp() {
    if ((System.currentTimeMillis() - exitTime) > 2000) {
        onMessage("再按一次退出应用程序");
        exitTime = System.currentTimeMillis();
    } else {
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancelAll();
        isExit = true;
        BApp.exitApp();
    }
}
 
Example 7
Source File: BaseNotificationHandler.java    From mobile-messaging-sdk-android with Apache License 2.0 5 votes vote down vote up
public void cancelAllNotifications() {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (notificationManager == null) {
        MobileMessagingLogger.e("Unable to get notification manager and cancel notifications");
        return;
    }

    notificationManager.cancelAll();
}
 
Example 8
Source File: VivoPushManager.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void clearNotification(Context context) {
    NotificationManager notificationManager =
            (NotificationManager) context.getApplicationContext().
                    getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
}
 
Example 9
Source File: IMNotificationManager.java    From sctalk with Apache License 2.0 5 votes vote down vote up
public void cancelAllNotifications() {
	logger.d("notification#cancelAllNotifications");
       if(null == ctx){
           return;
       }
	NotificationManager notifyMgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
	if (notifyMgr == null) {
		return;
	}
	notifyMgr.cancelAll();
}
 
Example 10
Source File: ScreenOnOffUpdateService.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
private void checkNotification(Context context) {
    String notificationPresence = AppPreference.getNotificationPresence(context);
    if (!"on_lock_screen".equals(notificationPresence)) {
        return;
    }
    if (NotificationUtils.isScreenLocked(context)) {
        NotificationUtils.weatherNotification(context, getLocationForNotification().getId());
    } else {
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancelAll();
    }
}
 
Example 11
Source File: MainActivity.java    From Lanmitm with GNU General Public License v2.0 5 votes vote down vote up
private void exit() {
	stopService(new Intent(this, ArpService.class));
	stopService(new Intent(this, HijackService.class));
	stopService(new Intent(this, SnifferService.class));
	NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
	nm.cancelAll();
	finish();
	android.os.Process.killProcess(android.os.Process.myPid());
}
 
Example 12
Source File: RNPushNotificationHelper.java    From react-native-push-notification-CE with MIT License 4 votes vote down vote up
public void clearNotifications() {
    Log.i(LOG_TAG, "Clearing alerts from the notification centre");

    NotificationManager notificationManager = notificationManager();
    notificationManager.cancelAll();
}
 
Example 13
Source File: NotifyUtil.java    From NotificationDemo with Apache License 2.0 4 votes vote down vote up
public static void cancelAll(Context context) {
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancelAll();
}
 
Example 14
Source File: AppHelper.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
public static void cancelAllNotifications(@NonNull Context context) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (notificationManager != null) {
        notificationManager.cancelAll();
    }
}
 
Example 15
Source File: StatusBarNotifier.java    From SmoothClicker with MIT License 4 votes vote down vote up
/**
 * Removes all notifications
 */
public void removeAllNotifications(){
    Logger.d(LOG_TAG, "Remove all notifications");
    NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancelAll();
}
 
Example 16
Source File: MainActivity.java    From WiFiAfterConnect with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        NotificationManager nm =  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		nm.cancelAll();
        wifiTools = WifiTools.getInstance(this);
        
        if (getIntent().getAction().equals(getString(R.string.action_reenable_wifi))) {
        	wifiTools.enableWifi();
        	finish();
        	return;
        }

        setContentView(R.layout.main_activity);
        
        toggleWifi = (ToggleButton) findViewById(R.id.toggleWifi);
//        toggleWifi.setEnabled(checkCallingOrSelfPermission("android.permission.CHANGE_NETWORK_STATE") 
//        						== PackageManager.PERMISSION_GRANTED);
        
        buttonAuthenticateNow = (Button) findViewById(R.id.buttonAuthenticateNow);
        
        lvRememberedSites = (ListView) findViewById(R.id.listKnownSites);
        deleteSelected = (Button)findViewById (R.id.buttonDeleteSelected);
        
        inetStatusInd = (TextView)findViewById (R.id.textInetStatusInd);
        
        // Create an empty adapter we will use to display the loaded data.
        // We pass null for the cursor, then update it in onLoadFinished()
        adapter = new WifiSitesCursorAdapter(this);
        lvRememberedSites.setAdapter(adapter);

        // Prepare the loader.  Either re-connect with an existing one,
        // or start a new one.
        getSupportLoaderManager().initLoader(0, null, this);
        
        // WE would really like to keep track of connectivity state so that our buttons 
        // reflect the state correctly
        IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
        receiverWifiConnect = new WifiBroadcastReceiver(){
    		@Override
    		public void onWifiConnectivityChange(Context context, boolean connected) {
    			refreshStatusIndicators ();
    		}
        };
        registerReceiver(receiverWifiConnect, intentFilter);
        
        // finally let us check if the device is connected to Internet presently
        checkInetOnline ();
    }
 
Example 17
Source File: NotifyManager.java    From LLApp with Apache License 2.0 4 votes vote down vote up
public static void hideAllNotify(Context context){
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
}
 
Example 18
Source File: MainActivity.java    From SecondScreen with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isDebugModeEnabled(boolean isClick) {
    SharedPreferences prefMain = U.getPrefMain(this);

    if(isClick && U.getPrefCurrent(this).getBoolean("not_active", true)) {
        clicks++;

        U.cancelToast();

        if(clicks > 5 && clicks < 10) {
            String message = String.format(getResources().getString(R.string.debug_mode_enabling), 10 - clicks);
            showDebugModeToast(message);
        } else if(clicks >= 10) {
            SharedPreferences.Editor editor = prefMain.edit();
            if(prefMain.getBoolean("debug_mode", false)) {
                editor.putBoolean("debug_mode", false);
                showDebugModeToast(getString(R.string.debug_mode_disabled));

                // Clean up leftover notifications
                NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                nm.cancelAll();

                // Clean up leftover dump files
                File file = new File(getExternalFilesDir(null), "prefCurrent.xml");
                File file2 = new File(getExternalFilesDir(null), "prefSaved.xml");
                File file3 = new File(getExternalFilesDir(null), "prefMain.xml");
                File file4 = new File(getExternalFilesDir(null), "prefNew.xml");
                file.delete();
                file2.delete();
                file3.delete();
                file4.delete();
            } else {
                editor.putBoolean("debug_mode", true);
                showDebugModeToast(getString(R.string.debug_mode_enabled));
            }

            editor.apply();
        }
    }

    return prefMain.getBoolean("debug_mode", false);
}
 
Example 19
Source File: GPPActivity.java    From GCMPushPlugin with MIT License 4 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    final NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
}
 
Example 20
Source File: NotificationUtils.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
public static void clearNotifications(Context context) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
}