List of usage examples for android.app PendingIntent FLAG_CANCEL_CURRENT
int FLAG_CANCEL_CURRENT
To view the source code for android.app PendingIntent FLAG_CANCEL_CURRENT.
Click Source Link
From source file:org.schabi.terminightor.NightKillerActivity.java
@Override protected void onResume() { Intent intent = new Intent(this, this.getClass()); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING | Intent.FLAG_ACTIVITY_SINGLE_TOP); pendingIntent = PendingIntent.getActivity(this, SpecialPendingIds.NIGHT_KILLER_READ_NFC_TAG_ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); IntentFilter[] intentFilters = new IntentFilter[] {}; nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFilters, null); Handler handler = new Handler(); handler.postDelayed(animRunnable, 500); hasStopped = false;//from w w w. j ava 2 s. c om super.onResume(); }
From source file:com.footprint.cordova.plugin.localnotification.LocalNotification.java
/** * Set an alarm.//from w ww . j a v a 2s .c om * * @param options * The options that can be specified per alarm. * @param doFireEvent * If the onadd callback shall be called. */ public static void add(Options options, boolean doFireEvent) { long triggerTime = options.getDate(); Intent intent = new Intent(context, Receiver.class).setAction("" + options.getId()) .putExtra(Receiver.OPTIONS, options.getJSONObject().toString()); AlarmManager am = getAlarmManager(); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); if (doFireEvent) { fireEvent("add", options.getId(), options.getJSON()); } am.set(AlarmManager.RTC_WAKEUP, triggerTime, pi); }
From source file:com.meiste.greg.ptw.QuestionAlarm.java
@Override protected void onHandleIntent(final Intent intent) { alarm_set = false;/*from w ww . j a v a 2 s. c o m*/ final Race race = Race.getInstance(this, intent.getIntExtra(RACE_ID, 0)); Util.log("Received question alarm for race " + race.getId()); synchronized (mSync) { if (mContainer == null) { try { mSync.wait(); } catch (final InterruptedException e) { } } } // Only show notification if user wants question reminders final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_QUESTIONS, true) && mContainer.getBoolean(GtmHelper.KEY_GAME_ENABLED)) { final Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.putExtra(PTW.INTENT_EXTRA_TAB, 1); final PendingIntent pi = PendingIntent.getActivity(this, PI_REQ_CODE, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); int defaults = 0; if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_VIBRATE, true)) defaults |= Notification.DEFAULT_VIBRATE; if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_LED, true)) defaults |= Notification.DEFAULT_LIGHTS; final NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_steering_wheel) .setTicker(getString(R.string.remind_questions_ticker, race.getName())) .setContentTitle(getString(R.string.app_name)).setContentText(race.getName()) .setContentIntent(pi).setAutoCancel(true).setDefaults(defaults).setSound(Uri .parse(prefs.getString(EditPreferences.KEY_NOTIFY_RINGTONE, PTW.DEFAULT_NOTIFY_SND))); getNM(this).notify(R.string.remind_questions_ticker, builder.build()); } else { Util.log("Ignoring question alarm since option is disabled"); } // Remember that user was reminded of this race Util.getState(this).edit().putInt(LAST_REMIND, race.getId()).apply(); // Reset alarm for the next race set(this); sendBroadcast(new Intent(PTW.INTENT_ACTION_RACE_ALARM)); }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncTask.java
protected Object work(Context context, DatabaseAdapter dba, String... params) throws ImportExportException { AccountManager accountManager = AccountManager.get(context); android.accounts.Account[] accounts = accountManager.getAccountsByType("com.google"); String accountName = MyPreferences.getFlowzrAccount(context); if (accountName == null) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, FlowzrSyncActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Builder mNotifyBuilder = new NotificationCompat.Builder(context); mNotifyBuilder.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon) .setWhen(System.currentTimeMillis()).setAutoCancel(true) .setContentTitle(context.getString(R.string.flowzr_sync)) .setContentText(context.getString(R.string.flowzr_choose_account)); nm.notify(0, mNotifyBuilder.build()); Log.i("Financisto", "account name is null"); throw new ImportExportException(R.string.flowzr_choose_account); }//www .j a va 2s. c o m Account useCredential = null; for (int i = 0; i < accounts.length; i++) { if (accountName.equals(((android.accounts.Account) accounts[i]).name)) { useCredential = accounts[i]; } } accountManager.getAuthToken(useCredential, "ah", false, new GetAuthTokenCallback(), null); return null; }
From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java
public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AutomuteAlarmReceiver.class); intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification timein Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using initial notification time and repeat interval time mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, RepeatTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:com.amlcurran.messages.telephony.SmsManagerOutputPort.java
public static PendingIntent resendPendingIntent(InFlightSmsMessage message, Context context) { return PendingIntent.getService(context, 0, resendMessageIntent(context, message), PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:org.wso2.emm.agent.services.DeviceStartupIntentReceiver.java
/** * Initiates device notifier on device startup. * @param context - Application context. *///from w ww. j a va 2 s . co m private void setRecurringAlarm(Context context) { this.resources = context.getApplicationContext().getResources(); String mode = Preference.getString(context, Constants.PreferenceFlag.NOTIFIER_TYPE); boolean isLocked = Preference.getBoolean(context, Constants.IS_LOCKED); String lockMessage = Preference.getString(context, Constants.LOCK_MESSAGE); if (lockMessage == null || lockMessage.isEmpty()) { lockMessage = resources.getString(R.string.txt_lock_activity); } if (isLocked) { Operation lockOperation = new Operation(); lockOperation.setId(DEFAULT_ID); lockOperation.setCode(Constants.Operation.DEVICE_LOCK); try { JSONObject payload = new JSONObject(); payload.put(Constants.ADMIN_MESSAGE, lockMessage); payload.put(Constants.IS_HARD_LOCK_ENABLED, true); lockOperation.setPayLoad(payload.toString()); OperationProcessor operationProcessor = new OperationProcessor(context); operationProcessor.doTask(lockOperation); } catch (AndroidAgentException e) { Log.e(TAG, "Error occurred while executing hard lock operation at the device startup"); } catch (JSONException e) { Log.e(TAG, "Error occurred while building hard lock operation payload"); } } int interval = Preference.getInt(context, context.getResources().getString(R.string.shared_pref_frequency)); if (interval == DEFAULT_INDEX) { interval = DEFAULT_INTERVAL; } if (mode == null) { mode = Constants.NOTIFIER_LOCAL; } if (Preference.getBoolean(context, Constants.PreferenceFlag.REGISTERED) && Constants.NOTIFIER_LOCAL.equals(mode.trim().toUpperCase(Locale.ENGLISH))) { long startTime = DEFAULT_TIME_MILLISECONDS; Intent alarmIntent = new Intent(context, AlarmReceiver.class); PendingIntent recurringAlarmIntent = PendingIntent.getBroadcast(context, DEFAULT_REQUEST_CODE, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, startTime, interval, recurringAlarmIntent); Log.d(TAG, "Setting up alarm manager for polling every " + interval + " milliseconds."); } }
From source file:org.frc836.database.DBSyncService.java
@Override public void onCreate() { super.onCreate(); // loadTimestamp(); initSync = !loadTimestamp();/*from w ww .ja va 2s . c om*/ password = ""; mTimerTask = new Handler(); dataTask = new SyncDataTask(); password = Prefs.getSavedPassword(getApplicationContext()); outgoing = new ArrayList<Map<String, String>>(); utils = new HttpUtils(); DBSyncService.version = getString(R.string.VersionID); mTimerTask.post(dataTask); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.service_notify_title)) .setContentText(getString(R.string.service_notify_text)).setOngoing(true).setWhen(0); Intent notifyIntent = new Intent(this, DashboardActivity.class); notifyIntent.setAction(Intent.ACTION_MAIN); notifyIntent.addCategory(Intent.CATEGORY_LAUNCHER); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_CANCEL_CURRENT); mBuilder.setContentIntent(intent); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(notifyID, mBuilder.build()); }
From source file:org.catrobat.catroid.utils.StatusBarNotificationManager.java
public int createCopyNotification(Context context, String programName) { if (context == null || programName == null) { return -1; }/*from w w w .j av a 2 s .c om*/ initNotificationManager(context); Intent copyIntent = new Intent(context, MainMenuActivity.class); copyIntent.setAction(Intent.ACTION_MAIN).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) .putExtra(EXTRA_PROJECT_NAME, programName); PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, copyIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationData data = new NotificationData(context, pendingIntent, R.drawable.ic_stat, programName, R.string.notification_copy_title_pending, R.string.notification_title_open, R.string.notification_copy_pending, R.string.notification_copy_finished); int id = createNotification(context, data); showOrUpdateNotification(id, 0); return id; }
From source file:com.cryart.sabbathschool.util.SSNotification.java
public static void showLessonNotification(Context context) { SSCore _SSCore = SSCore.getInstance(context); if (!SSCore.databaseExists()) return;/*from ww w . j a v a2 s . c o m*/ try { SSDay _SSDay = _SSCore.ssGetDay(_SSCore.ssTodaysDate()); Bitmap _SSLessonBitmap = SSHelper.getBitmapFromBase64(_SSDay._lesson_image); NotificationManager _SSNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Intent _SSContentIntent = new Intent(context, SSLoadingActivity.class); Intent _SSShareIntent = new Intent(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); String _SSBitmapLocation = Environment.getExternalStorageDirectory().toString() + "/" + SSConstants.SS_NOTIFICATION_LESSON_HERO_TMP_FILENAME; _SSContentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); _SSShareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); _SSShareIntent.setAction(Intent.ACTION_SEND); _SSShareIntent.putExtra(Intent.EXTRA_TEXT, _SSDay._day_name + " " + SSConstants.SS_SHARE_FB_LINK); _SSLessonBitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes); File f = new File(_SSBitmapLocation); try { f.createNewFile(); FileOutputStream fo = new FileOutputStream(f); fo.write(bytes.toByteArray()); } catch (IOException e) { e.printStackTrace(); } _SSShareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + _SSBitmapLocation)); _SSShareIntent.setType("*/*"); PendingIntent _SSPendingContentIntent = PendingIntent.getActivity(context, 0, _SSContentIntent, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent _SSPendingShareIntent = PendingIntent.getActivity(context, 0, Intent.createChooser(_SSShareIntent, "Share lesson to:"), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder _SSNotificationBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ss_app_icon_notification) .setColor(context.getResources().getColor(R.color.ss_primary)).setLargeIcon(_SSLessonBitmap) .setContentTitle(_SSDay._day_name) .setStyle(new NotificationCompat.BigPictureStyle().setBigContentTitle(_SSDay._day_name) .setSummaryText(_SSDay._day_name).bigPicture(_SSLessonBitmap)) .addAction(R.drawable.ss_ic_book_grey600_24dp, context.getString(R.string.ss_notification_read_lesson), _SSPendingContentIntent) .addAction(R.drawable.ss_ic_share_white_24dp, context.getString(R.string.ss_notification_share_lesson), _SSPendingShareIntent) .setAutoCancel(true).setContentIntent(_SSPendingContentIntent).setContentText(_SSDay._day_name); _SSNotificationManager.notify(1, _SSNotificationBuilder.build()); } catch (Exception e) { } }