Example usage for android.app NotificationManager cancel

List of usage examples for android.app NotificationManager cancel

Introduction

In this page you can find the example usage for android.app NotificationManager cancel.

Prototype

public void cancel(int id) 

Source Link

Document

Cancel a previously shown notification.

Usage

From source file:com.callba.phone.ui.NewFriendsMsgActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    listView = (ListView) findViewById(R.id.list);
    dao = new InviteMessgeDao(this);
    msgs = dao.getMessagesList();/*from   ww w .j  ava 2s .  c  o  m*/
    //adapter
    adapter = new NewFriendsMsgAdapter(this, 1, msgs);
    listView.setAdapter(adapter);
    dao.saveUnreadMessageCount(0);
    localBroadcastManager = LocalBroadcastManager.getInstance(this);
    broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            dao.saveUnreadMessageCount(0);
            msgs = dao.getMessagesList();
            adapter.notifyDataSetChanged();
            adapter = new NewFriendsMsgAdapter(NewFriendsMsgActivity.this, 1, msgs);
            listView.setAdapter(adapter);
        }
    };
    broadcastReceiver1 = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            dao.saveUnreadMessageCount(0);
            msgs = dao.getMessagesList();
            adapter.notifyDataSetChanged();
            adapter = new NewFriendsMsgAdapter(NewFriendsMsgActivity.this, 1, msgs);
            listView.setAdapter(adapter);
        }
    };
    localBroadcastManager.registerReceiver(broadcastReceiver, new IntentFilter(Constant.ACTION_GROUP_NOTIFY));
    localBroadcastManager.registerReceiver(broadcastReceiver1,
            new IntentFilter(Constant.ACTION_CONTACT_CHANAGED));
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(0526);
}

From source file:org.maikelwever.droidpile.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // This is enables on releases. TODO (reminder)
    //Crashlytics.start(this);

    setContentView(R.layout.activity_main);
    final ActionBar actionBar = getSupportActionBar();

    viewPager = (ViewPager) findViewById(R.id.pager);
    pagerAdapter = new TabsPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(pagerAdapter);/*  w  w w .  ja v a  2 s.  co  m*/

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        @Override
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

        }

        @Override
        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

        }
    };

    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getSupportActionBar().setSelectedNavigationItem(position);
        }
    });

    actionBar.setHomeButtonEnabled(false);
    for (String tab_name : tabs) {
        actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(tabListener));
    }

    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancel(1234);

}

From source file:org.namelessrom.devicecontrol.services.WebServerService.java

public void cancelNotification() {
    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(NOTIFICATION_ONGOING);
}

From source file:com.android.my.calendar.alerts.DismissAlarmsService.java

@Override
public void onHandleIntent(Intent intent) {
    if (AlertService.DEBUG) {
        Log.d(TAG, "onReceive: a=" + intent.getAction() + " " + intent.toString());
    }/*  w  w w . jav a  2s  .c om*/

    long eventId = intent.getLongExtra(AlertUtils.EVENT_ID_KEY, -1);
    long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1);
    long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1);
    long[] eventIds = intent.getLongArrayExtra(AlertUtils.EVENT_IDS_KEY);
    long[] eventStarts = intent.getLongArrayExtra(AlertUtils.EVENT_STARTS_KEY);
    int notificationId = intent.getIntExtra(AlertUtils.NOTIFICATION_ID_KEY, -1);
    List<AlarmId> alarmIds = new LinkedList<AlarmId>();

    Uri uri = CalendarAlerts.CONTENT_URI;
    String selection;

    // Dismiss a specific fired alarm if id is present, otherwise, dismiss all alarms
    if (eventId != -1) {
        alarmIds.add(new AlarmId(eventId, eventStart));
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " + CalendarAlerts.EVENT_ID
                + "=" + eventId;
    } else if (eventIds != null && eventIds.length > 0 && eventStarts != null
            && eventIds.length == eventStarts.length) {
        selection = buildMultipleEventsQuery(eventIds);
        for (int i = 0; i < eventIds.length; i++) {
            alarmIds.add(new AlarmId(eventIds[i], eventStarts[i]));
        }
    } else {
        // NOTE: I don't believe that this ever happens.
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED;
    }

    GlobalDismissManager.dismissGlobally(getApplicationContext(), alarmIds);

    ContentResolver resolver = getContentResolver();
    ContentValues values = new ContentValues();
    values.put(PROJECTION[COLUMN_INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
    resolver.update(uri, values, selection, null);

    // Remove from notification bar.
    if (notificationId != -1) {
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(notificationId);
    }

    if (SHOW_ACTION.equals(intent.getAction())) {
        // Show event on Calendar app by building an intent and task stack to start
        // EventInfoActivity with AllInOneActivity as the parent activity rooted to home.
        Intent i = AlertUtils.buildEventViewIntent(this, eventId, eventStart, eventEnd);

        TaskStackBuilder.create(this).addParentStack(EventInfoActivity.class).addNextIntent(i)
                .startActivities();
    }
}

From source file:com.klinker.android.twitter.activities.compose.NotificationComposeSecondAcc.java

@Override
public void setUpReplyText() {
    // mark the messages as read here
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancel(1);
    mNotificationManager.cancel(9);/*from  ww w  .j av  a  2  s .c  o m*/

    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    Context context = getApplicationContext();
    int currentAccount = sharedPrefs.getInt("current_account", 1);

    if (currentAccount == 1) {
        currentAccount = 2;
    } else {
        currentAccount = 1;
    }

    useAccOne = false;
    useAccTwo = true;

    NetworkedCacheableImageView pic = (NetworkedCacheableImageView) findViewById(R.id.profile_pic);
    HoloTextView currentName = (HoloTextView) findViewById(R.id.current_name);

    if (settings.roundContactImages) {
        pic.loadImage(settings.secondProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
    } else {
        pic.loadImage(settings.secondProfilePicUrl, false, null);
    }

    currentName.setText("@" + settings.secondScreenName);

    MentionsDataSource.getInstance(context).markAllRead(currentAccount);
    sharedPrefs.edit().putInt("dm_unread_" + currentAccount, 0).commit();

    // set up the reply box
    reply.setText(sharedPrefs.getString("from_notification_second", ""));
    reply.setSelection(reply.getText().toString().length());
    notiId = sharedPrefs.getLong("from_notification_long_second", 0);
    replyText = sharedPrefs.getString("from_notification_text_second", "");

    sharedPrefs.edit().putLong("from_notification_id_second", 0).commit();
    sharedPrefs.edit().putString("from_notification_text_second", "").commit();
    sharedPrefs.edit().putString("from_notification_second", "").commit();
    sharedPrefs.edit().putBoolean("from_notification_bool_second", false).commit();

    // try from android wear device
    CharSequence voiceReply = getVoiceReply(getIntent());
    if (voiceReply != null) {
        if (!voiceReply.equals("")) {
            // set the text
            reply.append(voiceReply);

            // send the message
            doneClick();

            finish();
        }
    }
}

From source file:com.klinker.android.twitter.ui.compose.NotificationComposeSecondAcc.java

@Override
public void setUpReplyText() {
    // mark the messages as read here
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancel(1);
    mNotificationManager.cancel(9);/*from  ww w. j  a v  a2  s.c o  m*/

    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    Context context = getApplicationContext();
    int currentAccount = sharedPrefs.getInt("current_account", 1);

    if (currentAccount == 1) {
        currentAccount = 2;
    } else {
        currentAccount = 1;
    }

    useAccOne = false;
    useAccTwo = true;

    NetworkedCacheableImageView pic = (NetworkedCacheableImageView) findViewById(R.id.profile_pic);
    HoloTextView currentName = (HoloTextView) findViewById(R.id.current_name);

    if (settings.roundContactImages) {
        pic.loadImage(settings.secondProfilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
    } else {
        pic.loadImage(settings.secondProfilePicUrl, false, null);
    }

    currentName.setText("@" + settings.secondScreenName);

    MentionsDataSource.getInstance(context).markAllRead(currentAccount);
    sharedPrefs.edit().putInt("dm_unread_" + currentAccount, 0).commit();

    // set up the reply box
    reply.setText(sharedPrefs.getString("from_notification_second", ""));
    reply.setSelection(reply.getText().toString().length());
    notiId = sharedPrefs.getLong("from_notification_long_second", 0);
    replyText = sharedPrefs.getString("from_notification_text_second", "");

    sharedPrefs.edit().putLong("from_notification_id_second", 0).commit();
    sharedPrefs.edit().putString("from_notification_text_second", "").commit();
    sharedPrefs.edit().putString("from_notification_second", "").commit();
    sharedPrefs.edit().putBoolean("from_notification_bool_second", false).commit();

    // try from android wear device
    CharSequence voiceReply = getVoiceReply(getIntent());
    if (voiceReply != null) {
        if (!voiceReply.equals("")) {
            // set the text
            reply.append(voiceReply);

            // send the message
            doneClick();

            finish();
        }
    }
}

From source file:jdev.guardian.service.ServiceHelper.java

private void stop() {
    if (isRunning()) {
        NotificationManager notificationManager = (NotificationManager) cordova.getActivity()
                .getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancel(GuardianService.NOTIFICATION_ID);
        cordova.getActivity().stopService(serviceIntent);
    }//from   w w  w.  jav  a 2s . com
}

From source file:org.solovyev.android.messenger.UnreadMessagesNotifier.java

@Override
public void onEvent(@Nonnull MessengerEvent event) {
    switch (event.getType()) {
    case unread_messages_count_changed:
        final Integer unreadMessagesCount = event.getDataAsInteger();

        final NotificationManager nm = getNotificationManager();

        // cancel last notification (if needed new notification will be created later)
        nm.cancel(NOTIFICATION_ID_UNREAD_MESSAGES);

        if (unreadMessagesCount > 0) {
            if (!isAppShown()) {
                // todo serso: make proper notification (unread messages text, small icon, etc)
                // we are not at the top => show notification
                final NotificationCompat.Builder nb = new NotificationCompat.Builder(context);
                nb.setSmallIcon(R.drawable.mpp_sb_unread_messages_icon);
                nb.setContentTitle(context.getResources().getQuantityString(
                        R.plurals.mpp_unread_messages_count_notification, unreadMessagesCount,
                        unreadMessagesCount));
                nb.setContentText(context.getString(R.string.mpp_notification_text));
                nb.setContentIntent(getActivity(context, 0, newUnreadMessagesStartIntent(context), 0));
                nb.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                nm.notify(NOTIFICATION_ID_UNREAD_MESSAGES, nb.getNotification());
            }/*from   w ww .ja  v a  2 s  .c o m*/
        }
        break;
    }
}

From source file:com.krossovochkin.kwitter.activities.MainActivity.java

@Override
public void onPostSendTweet(boolean isTweetSent) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.cancel(NOTIFICATION_ID_SENDING_TWEET);

    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    if (!isTweetSent) {

        Notification notification = new NotificationCompat.Builder(this)
                .setContentTitle(getString(R.string.app_name))
                .setContentText(getString(R.string.error_sendgin_tweet)).setSmallIcon(R.drawable.ic_launcher)
                .setContentIntent(pendingIntent).build();
        notificationManager.notify(NOTIFICATION_ID_SENDING_TWEET, notification);
    }/*from w ww.  j  a  va  2 s.co m*/
}

From source file:com.iniciacomunicacion.devicenotification.DeviceNotification.java

/**
 * Cancel a specific notification that was previously registered.
 * /*from  ww  w.j a v a2  s  .c  o  m*/
 * @param callbackContext, Callback context of the request from Cordova
 * @param id, notification id registered using add()
 * @see add
 */
public void cancel(CallbackContext callbackContext, int id) {
    NotificationManager notificationManager = (NotificationManager) cordova.getActivity()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(id);
}