下面列出了android.app.NotificationManager#cancelAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
}
}
@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());
}
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;
}
}
}
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();
}
}
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();
}
@Override
public void clearNotification(Context context) {
NotificationManager notificationManager =
(NotificationManager) context.getApplicationContext().
getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
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());
}
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();
}
}
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();
}
@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;
}
public static void logout()
{
BaseApplication.getInstance().onLogout();
NotificationManager nm = (NotificationManager) BaseApplication.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancelAll();
setSessionUser(null);
Session.getActiveSession().closeAndClearTokenInformation();
}
@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 ();
}
public static void clearNotifications(Context context) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
@Override
protected void onResume() {
super.onResume();
final NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
@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);
}
public static void hideAllNotify(Context context){
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
public void clearNotifications() {
Log.i(LOG_TAG, "Clearing alerts from the notification centre");
NotificationManager notificationManager = notificationManager();
notificationManager.cancelAll();
}
/**
* Removes all notifications
*/
public void removeAllNotifications(){
Logger.d(LOG_TAG, "Remove all notifications");
NotificationManager nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancelAll();
}
public static void cancelAllNotifications(@NonNull Context context) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.cancelAll();
}
}
public static void cancelAll(Context context) {
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancelAll();
}