Example usage for android.app PendingIntent cancel

List of usage examples for android.app PendingIntent cancel

Introduction

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

Prototype

public void cancel() 

Source Link

Document

Cancel a currently active PendingIntent.

Usage

From source file:Main.java

public static synchronized void cancelServiceAlarm(Context context, Intent intent, int identifier) {

    final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent pi = PendingIntent.getService(context, identifier, intent,
            PendingIntent.FLAG_NO_CREATE);
    if (pi != null) {
        am.cancel(pi);//from   w w w  .  ja va 2  s .co  m
        pi.cancel();
    }

}

From source file:com.sentaroh.android.SMBSync.NotificationUtil.java

final static public void showNoticeMsg(Context context, GlobalParameters gwa, String msg) {
    clearNotification(gwa);//  ww w  .  ja v  a 2 s .co  m
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder
            //         .setTicker(gwa.notificationAppName)
            .setOngoing(false).setAutoCancel(true).setSmallIcon(R.drawable.ic_48_smbsync_wait)
            .setContentTitle(context.getString(R.string.app_name)).setContentText(msg)
            .setWhen(System.currentTimeMillis())
    //         .addAction(action_icon, action_title, action_pi)
    ;

    boolean valid_log_file_exists = false;
    if (!gwa.currentLogFilePath.equals("") && !gwa.settingLogOption.equals("0")) {
        File lf = new File(gwa.currentLogFilePath);
        if (lf.exists())
            valid_log_file_exists = true;
    }
    if (valid_log_file_exists) {
        Intent br_log_intent = new Intent(android.content.Intent.ACTION_VIEW);
        br_log_intent.setDataAndType(Uri.parse("file://" + gwa.currentLogFilePath), "text/plain");
        PendingIntent br_log_pi = PendingIntent.getActivity(context, 0, br_log_intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(br_log_pi);
    } else {
        Intent dummy_intent = new Intent(context, SMBSyncMain.class);
        PendingIntent dummy_pi = PendingIntent.getActivity(context, 0, dummy_intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        dummy_pi.cancel();
        builder.setContentIntent(dummy_pi);
    }

    gwa.notificationManager.notify(R.string.app_name, builder.build());
}

From source file:com.sentaroh.android.SMBSync2.NotificationUtil.java

final static public void showNoticeMsg(Context context, GlobalParameters gwa, String msg) {
    clearNotification(gwa);//from   ww w .j  av a2 s.co  m
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder
            //         .setTicker(gwa.notificationAppName)
            .setOngoing(false).setAutoCancel(true).setSmallIcon(gwa.notificationSmallIcon)//smbsync_animation)
            .setLargeIcon(gwa.notificationLargeIcon).setContentTitle(context.getString(R.string.app_name))
            .setContentText(msg).setWhen(System.currentTimeMillis())
    //         .addAction(action_icon, action_title, action_pi)
    ;

    boolean valid_log_file_exists = false;
    if (!LogUtil.getLogFilePath(gwa).equals("") && !gwa.settingLogOption) {
        File lf = new File(LogUtil.getLogFilePath(gwa));
        if (lf.exists())
            valid_log_file_exists = true;
    }
    if (valid_log_file_exists) {
        Intent br_log_intent = new Intent(android.content.Intent.ACTION_VIEW);
        br_log_intent.setDataAndType(Uri.parse("file://" + LogUtil.getLogFilePath(gwa)), "text/plain");
        PendingIntent br_log_pi = PendingIntent.getActivity(context, 0, br_log_intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(br_log_pi);
    } else {
        Intent dummy_intent = new Intent(context, ActivityMain.class);
        PendingIntent dummy_pi = PendingIntent.getActivity(context, 0, dummy_intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        dummy_pi.cancel();
        builder.setContentIntent(dummy_pi);
    }

    gwa.notificationManager.notify(R.string.app_name, builder.build());
}

From source file:org.leopub.mat.service.MessageService.java

public static void cancelUpdate(Context context) {
    Intent i = new Intent(context, MessageService.class);
    PendingIntent pi = PendingIntent.getService(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pi);/*from  ww  w . j  a v  a  2s  .  c om*/
    pi.cancel();
}

From source file:org.chromium.ChromeNotifications.java

private static void triggerJavascriptEventNow(Context context, ComponentName componentName,
        EventInfo eventInfo) {//www . ja va2  s. c  om
    Intent intent = new Intent();
    intent.setComponent(componentName);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    if (NOTIFICATION_CLICKED_ACTION.equals(eventInfo.action)) {
        webView.sendJavascript("chrome.notifications.triggerOnClicked('" + eventInfo.notificationId + "')");
        context.startActivity(intent);
    } else if (NOTIFICATION_CLOSED_ACTION.equals(eventInfo.action)) {
        PendingIntent pendingIntent = makePendingIntent(context, componentName, NOTIFICATION_CLICKED_ACTION,
                eventInfo.notificationId, -1, PendingIntent.FLAG_NO_CREATE);
        if (pendingIntent != null) {
            pendingIntent.cancel();
        }
        webView.sendJavascript("chrome.notifications.triggerOnClosed('" + eventInfo.notificationId + "')");
    } else if (NOTIFICATION_BUTTON_CLICKED_ACTION.equals(eventInfo.action)) {
        webView.sendJavascript("chrome.notifications.triggerOnButtonClicked('" + eventInfo.notificationId
                + "', " + eventInfo.buttonIndex + ")");
        context.startActivity(intent);
    }
}

From source file:org.ohmage.reminders.notif.Notifier.java

private static void cancelAlarm(Context context, String action) {
    AlarmManager alarmMan = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    Intent i = new Intent(context, NotifReceiver.class).setAction(action);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_NO_CREATE);

    if (pi != null) {
        alarmMan.cancel(pi);/*  w  ww  .ja  v a 2  s .  c o m*/
        pi.cancel();
    }
}

From source file:org.ohmage.reminders.notif.Notifier.java

private static void cancelAllAlarms(Context context, int trigId) {
    AlarmManager alarmMan = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    Intent i = new Intent(context, NotifReceiver.class).setAction(ACTION_EXPIRE_ALM);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_NO_CREATE);

    if (pi != null) {
        alarmMan.cancel(pi);//  w  w w  .  j  a  v a 2  s.  c o  m
        pi.cancel();
    }

    i = new Intent(context, NotifReceiver.class).setAction(ACTION_REPEAT_ALM);
    pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_NO_CREATE);

    if (pi != null) {
        alarmMan.cancel(pi);
        pi.cancel();
    }
}

From source file:org.chromium.ChromeAlarms.java

private void cancelAlarm(final String name) {
    PendingIntent pendingIntent = makePendingIntentForAlarm(name, PendingIntent.FLAG_NO_CREATE);
    if (pendingIntent != null) {
        alarmManager.cancel(pendingIntent);
        pendingIntent.cancel();
    }/*ww  w . ja  va2s . co m*/
}

From source file:com.vaporwarecorp.mirror.component.AppManagerImpl.java

@Override
public void cancelPendingIntent(Intent intent) {
    PendingIntent pendingIntent = PendingIntent.getBroadcast(mApplication, 0, intent, 0);
    ((AlarmManager) mApplication.getSystemService(ALARM_SERVICE)).cancel(pendingIntent);
    pendingIntent.cancel();
}

From source file:de.incoherent.suseconferenceclient.tasks.CheckForUpdatesTask.java

@Override
protected Long doInBackground(Void... params) {
    String kUrl = "https://conference.opensuse.org/osem/api/v1/conferences/gRNyOIsTbvCfJY5ENYovBA";
    if (kUrl.length() <= 0)
        return 0l;

    String updatesUrl = mConference.getUrl() + "/updates.json";
    int lastUpdateRevision = mDb.getLastUpdateValue(mConference.getSqlId());
    int revisionLevel = lastUpdateRevision;

    try {//  www.ja va  2s. c o m
        JSONObject updateReply = HTTPWrapper.get(updatesUrl);
        if (updateReply == null)
            return 0l;
        int newLevel = updateReply.getInt("revision");
        if (newLevel > revisionLevel) {
            long id = mConference.getSqlId();
            // Cache favorites and alerts
            List<String> favoriteGuids = mDb.getFavoriteGuids(id);
            List<Event> alerts = mDb.getAlertEvents(id);
            List<String> alertGuids = new ArrayList<String>();
            // Now cancel all of the outstanding alerts, in case
            // a talk has been moved
            AlarmManager manager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
            for (Event e : alerts) {
                alertGuids.add("\"" + e.getGuid() + "\"");
                Log.d("SUSEConferences", "Removing an alert for " + e.getTitle());

                Intent intent = new Intent(mContext, AlarmReceiver.class);
                intent.putExtras(ScheduleDetailsActivity.generateAlarmIntentBundle(mContext, e));
                PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext,
                        intent.getStringExtra("intentId").hashCode(), intent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                manager.cancel(pendingIntent);
                pendingIntent.cancel();
            }

            // Now clear the DB
            mDb.clearDatabase(id);
            // Download schedule
            ConferenceCacher cacher = new ConferenceCacher(new ConferenceCacherProgressListener() {
                @Override
                public void progress(String progress) {
                    publishProgress(progress);
                }
            });

            long val = cacher.cacheConference(mConference, mDb);
            mErrorMessage = cacher.getLastError();
            if (val == -1) {
                mDb.setConferenceAsCached(id, 0);
            } else {
                mDb.setLastUpdateValue(id, newLevel);
                mDb.toggleEventsInMySchedule(favoriteGuids);
                mDb.toggleEventAlerts(alertGuids);
                alerts = mDb.getAlertEvents(id);
                // ... And re-create the alerts, if they are in the future
                Date currentDate = new Date();
                for (Event e : alerts) {
                    if (currentDate.after(e.getDate()))
                        continue;
                    Log.d("SUSEConferences", "Adding an alert for " + e.getTitle());
                    alertGuids.add("\"" + e.getGuid() + "\"");
                    Intent intent = new Intent(mContext, AlarmReceiver.class);
                    intent.putExtras(ScheduleDetailsActivity.generateAlarmIntentBundle(mContext, e));
                    PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext,
                            intent.getStringExtra("intentId").hashCode(), intent,
                            PendingIntent.FLAG_UPDATE_CURRENT);
                    manager.set(AlarmManager.RTC_WAKEUP, e.getDate().getTime() - 300000, pendingIntent);
                }

            }
            return val;
        } else {
            return 0l;
        }
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}