List of usage examples for android.app NotificationManager cancel
public void cancel(int id)
From source file:com.kiandastream.musicplayer.MusicService.java
public void clearNotification() { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID); }
From source file:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java
private void dismissUpdateNotification() { if (mUpdateNotification == null) return;/*from w w w.j av a 2s . co m*/ Log.d(TAG, "dismissUpdateNotification"); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(UPDATE_NOTIFICATION_ID); mUpdateNotification = null; }
From source file:com.dwdesign.tweetings.activity.HomeActivity.java
public void closeStream() { if (mPreferences.getBoolean(PREFERENCE_KEY_STREAMING_ENABLED, false) == true) { if (mService != null && twitterStream != null) { try { twitterStream.shutdown(); if (mPreferences.getBoolean(PREFERENCE_KEY_STREAMING_NOTIFICATION, false) == true) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID_STREAMING); }//from ww w. ja v a2 s . c om } catch (final Exception e) { e.printStackTrace(); } } } }
From source file:com.nutsuser.ridersdomain.activities.MyGcmListenerService.java
private void createNotification(String title, String body) { Context context = getBaseContext(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.app_icon).setContentTitle(title).setContentText(body); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Intent notificationIntent = new Intent(context, NotificationListActivity.class); ///*from w w w . j a va 2s.c o m*/ // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP // | Intent.FLAG_ACTIVITY_SINGLE_TOP); // // PendingIntent intent = PendingIntent.getActivity(context, 0, // notificationIntent, 0); Intent resultIntent = new Intent(this, NotificationListActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(NotificationListActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build()); mNotificationManager.cancel(MESSAGE_NOTIFICATION_ID); }
From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java
private void deleteNotification() { if (notificationHolderId != null) { experimentProviderUtil.deleteNotification(notificationHolderId); }// w ww. ja v a2 s .co m if (shouldExpireNotificationHolder) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(new Long(notificationHolderId).intValue()); shouldExpireNotificationHolder = false; } }
From source file:com.klinker.deskclock.alarms.AlarmNotifications.java
public static void showLowPriorityNotification(Context context, AlarmInstance instance) { Log.v("Displaying low priority notification for alarm instance: " + instance.mId); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Resources resources = context.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(resources.getString(R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText(context, instance)) .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(false).setAutoCancel(false) .setPriority(NotificationCompat.PRIORITY_DEFAULT); // Setup up hide notification Intent hideIntent = AlarmStateManager.createStateChangeIntent(context, "DELETE_TAG", instance, AlarmInstance.HIDE_NOTIFICATION_STATE); notification.setDeleteIntent(PendingIntent.getBroadcast(context, instance.hashCode(), hideIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance, AlarmInstance.DISMISSED_STATE); notification.addAction(android.R.drawable.ic_menu_close_clear_cancel, resources.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getBroadcast(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId); viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX); viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId); viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); nm.cancel(instance.hashCode()); nm.notify(instance.hashCode(), notification.build()); }
From source file:com.deepak.myclock.alarms.AlarmNotifications.java
public static void showLowPriorityNotification(Context context, AlarmInstance instance) { Log.v("Displaying low priority notification for alarm instance: " + instance.mId); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Resources resources = context.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(resources.getString(R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText(context, instance)) .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(false).setAutoCancel(false) .setPriority(NotificationCompat.PRIORITY_DEFAULT); // Setup up hide notification Intent hideIntent = AlarmStateManager.createStateChangeIntent(context, "DELETE_TAG", instance, AlarmInstance.HIDE_NOTIFICATION_STATE); notification.setDeleteIntent(PendingIntent.getBroadcast(context, instance.hashCode(), hideIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance, AlarmInstance.DISMISSED_STATE); notification.addAction(android.R.drawable.ic_menu_close_clear_cancel, resources.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getBroadcast(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; Intent viewAlarmIntent = Alarm.createIntent(context, MainActivity.class, alarmId); //viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX); viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId); viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); nm.cancel(instance.hashCode()); nm.notify(instance.hashCode(), notification.build()); }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** Cancel system notification */ private void cancelSystemNotification(EngagementReachInteractiveContent content) { if (content.isSystemNotification()) { NotificationManager notificationManager = (NotificationManager) mContext .getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(getNotifier(content).getNotificationId(content)); }//from w ww . j ava 2 s. c om }
From source file:cn.devit.app.ip_messenger.MainActivity.java
void setupListener() { handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case ADD_USER: userList.add((UserData) msg.obj); // view? if (sendView != null && sendView.userList != null) { sendView.userList.setUserList(userList); } else { // TODO a deferred event must notice. }//from ww w.j a va2 s. c o m break; case RECEIVE_MSG: final PigeonMessage m = (PigeonMessage) msg.obj; String tip = m.getContent(); if (m.hasAttachements()) { String attachementsDesc = ""; for (AttachementLink item : m.getAttachements()) { attachementsDesc += item.getFilename(); } tip += "" + attachementsDesc; final NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); new AlertDialog.Builder(MainActivity.this).setIcon(android.R.drawable.ic_dialog_info) .setTitle("").setMessage(attachementsDesc) .setPositiveButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO reject file notificationManager.cancel(m.hashCode()); startDownloadAttachment(m); } }).setNegativeButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d("main", "cancel notify NO.=" + m.hashCode()); notificationManager.cancel(m.hashCode()); // notificationManager.cancelAll(); new Thread(new Runnable() { @Override public void run() { network.rejectAttachement(m); } }).start(); } }).show(); Intent notificationIntent = new Intent(MainActivity.this, MainActivity.class); // ??Activity PendingIntent contentItent = PendingIntent.getActivity(MainActivity.this, 0, notificationIntent, 0); // TODO move to method. Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("?") .setContentText(attachementsDesc).setStyle(new NotificationCompat.InboxStyle()) .setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL) .addAction(0, "agree", contentItent).addAction(0, "dismiss", contentItent).build(); // new Notification.Builder( // getApplicationContext()).setTicker("?") // // .setLargeIcon(R.drawable.ic_launcher) // .setSmallIcon(R.drawable.ic_launcher).build(); // notification.flags |= // (Notification.FLAG_AUTO_CANCEL); // notification.defaults = Notification.DEFAULT_ALL; // String title = "?"; // NotificationNotificationManager Log.d("main", "show notify NO.=" + m.hashCode()); notificationManager.notify(m.hashCode(), notification); } Toast.makeText(getApplication(), tip, Toast.LENGTH_SHORT).show(); DummyContent1.addItem(String.valueOf(i++), m.getSender().getUsername(), tip); break; default: Toast.makeText(getApplication(), String.valueOf(msg.obj), Toast.LENGTH_SHORT).show(); } ; } }; listener.handler = handler; }
From source file:mx.klozz.xperience.tweaker.fragments.BatteryInfo.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.battery_info, root, false); mBattery_Percent = (TextView) view.findViewById(R.id.battery_percent); mBattery_volt = (TextView) view.findViewById(R.id.battery_volt); mBattery_Status = (TextView) view.findViewById(R.id.battery_status); mBatteryIcon = (ImageView) view.findViewById(R.id.battery_icon); //Checamos si existe algo relacionado con la direccion de voltajes if (new File(BAT_VOLT_PATH).exists()) { int volt = Integer.parseInt(Helpers.LeerUnaLinea(BAT_VOLT_PATH));//vemos si existe el directorio if (volt > 5000) volt = (int) Math.round(volt / 1000.0);//Convertimos a microvolts mBattery_volt.setText(volt + " mV");//Hacemos visible los datos mBatteryIcon.setVisibility(ImageView.GONE); mBattery_volt.setVisibility(TextView.VISIBLE); mBattery_volt.setOnClickListener(new View.OnClickListener() { @Override/*from ww w.j a v a2 s . c o m*/ public void onClick(View view) { Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null) startActivity(powerUsageIntent); } }); mBattery_volt.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { mBatteryIcon.setVisibility(ImageView.VISIBLE); mBattery_volt.setVisibility(TextView.GONE); return true; } }); } else { mBatteryIcon.setVisibility(ImageView.VISIBLE); mBattery_volt.setVisibility(TextView.GONE); mBatteryIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); startActivity(powerUsageIntent); } catch (Exception e) { } } }); } mFastChargePath = Helpers.fastcharge_path(); if (mFastChargePath != null) { no_settings = false; mFastChargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob); mFastChargeOnBoot.setChecked( mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.LeerUnaLinea(mFastChargePath).equals("1"))); mFastChargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton v, boolean checked) { mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply(); final NotificationManager NM = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (checked) { new CMDProcessor().su.runWaitFor("busybox exho 1 > " + mFastChargePath); Notification N = new Notification.Builder(context) .setContentTitle(context.getText(R.string.app_name)) .setContentText(context.getText(R.string.fast_charge_notification_title)) .setTicker(context.getText(R.string.fast_charge_notification_title)) .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis()) .getNotification(); NM.notify(1337, N); } else { new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath); NM.cancel(1337); } } }); } else { LinearLayout mPart = (LinearLayout) view.findViewById(R.id.fastcharge_layout); mPart.setVisibility(LinearLayout.GONE); } if (no_settings) { LinearLayout NS = (LinearLayout) view.findViewById(R.id.no_settings); NS.setVisibility(LinearLayout.VISIBLE); } return view; }