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:net.bither.util.SystemUtil.java
public static void nmNotifyDefault(NotificationManager nm, Context context, int notifyId, Intent intent, String title, String contentText, int iconId) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(iconId);/*from w w w . j a v a 2 s . c om*/ builder.setContentText(contentText); builder.setContentTitle(title); builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); builder.setWhen(System.currentTimeMillis()); Notification notification = null; notification = builder.build(); notification.defaults = Notification.DEFAULT_SOUND; notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0xFF84E4FA; notification.ledOnMS = 3000; notification.ledOffMS = 2000; nm.notify(notifyId, notification); }
From source file:org.pixmob.freemobile.netstat.SyncServiceTesting.java
public static void schedule(Context context, boolean enabled) { final Context appContext = context.getApplicationContext(); final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent syncIntent = PendingIntent.getService(appContext, 0, new Intent(appContext, SyncServiceTesting.class), PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(syncIntent);//ww w . j a v a 2 s . c o m if (enabled) { // Set the sync period. long period = AlarmManager.INTERVAL_HOUR; final int syncErrors = context.getSharedPreferences(INTERNAL_SP_NAME, MODE_PRIVATE) .getInt(INTERNAL_SP_KEY_SYNC_ERRORS, 0); if (syncErrors != 0) { // When there was a sync error, the sync period is longer. period = AlarmManager.INTERVAL_HOUR * Math.min(syncErrors, MAX_SYNC_ERRORS); } // Add a random time to prevent concurrent requests for the server. final long fuzz = RANDOM.nextInt(1000 * 60 * 30); period += fuzz; if (DEBUG) { Log.d(TAG, "Scheduling synchronization: next in " + (period / 1000 / 60) + " minutes"); } final long syncTime = System.currentTimeMillis() + period; am.set(AlarmManager.RTC_WAKEUP, syncTime, syncIntent); } else { if (DEBUG) { Log.d(TAG, "Synchronization schedule canceled"); } } }
From source file:mchs.neverforget.services.NotificationIntentService.java
public static void cancelCustomRecurrentNotificationAlarm(Context context, int customId) { //Toast.makeText(context, "cancelCustomRecurrentNotificationAlarm"+customId, Toast.LENGTH_SHORT).show(); Intent intent = new Intent(context, NotificationIntentService.class); if (customId == 1) { intent.setAction(ACTION_NOTIFY_CUSTOM1); } else if (customId == 2) { intent.setAction(ACTION_NOTIFY_CUSTOM2); } else if (customId == 3) { intent.setAction(ACTION_NOTIFY_CUSTOM3); }/*from www. j a va 2s . c o m*/ PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); alarmManager.cancel(pendingIntent); }
From source file:org.totschnig.myexpenses.service.AutoBackupService.java
@Override protected void doWakefulWork(Intent intent) { String action = intent.getAction(); if (ACTION_AUTO_BACKUP.equals(action)) { Log.i("DEBUG", "now doing backup"); Result result = GenericTask.doBackup(); String notifTitle = Utils.concatResStrings(this, " ", R.string.app_name, R.string.contrib_feature_auto_backup_label); if (result.success) { int remaining = ContribFeature.AUTO_BACKUP.recordUsage(); if (remaining < 1) { CharSequence content = TextUtils.concat(getText(R.string.warning_auto_backup_limit_reached), " ", ContribFeature.AUTO_BACKUP.buildRemoveLimitation(this, true)); Intent contribIntent = new Intent(this, ContribInfoDialogActivity.class); contribIntent.putExtra(ContribInfoDialogActivity.KEY_FEATURE, ContribFeature.AUTO_BACKUP); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_home_dark).setContentTitle(notifTitle) .setContentText(content) .setContentIntent(PendingIntent.getActivity(this, 0, contribIntent, PendingIntent.FLAG_CANCEL_CURRENT)) .setStyle(new NotificationCompat.BigTextStyle().bigText(content)); Notification notification = builder.build(); notification.flags = Notification.FLAG_AUTO_CANCEL; ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification); }//from w w w . j a v a2s .c om } else { String content = result.print(this); Intent preferenceIntent = new Intent(this, MyPreferenceActivity.class); preferenceIntent.putExtra(MyPreferenceActivity.KEY_OPEN_PREF_KEY, PrefKey.APP_DIR.getKey()); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_home_dark).setContentTitle(notifTitle).setContentText(content) .setContentIntent(PendingIntent.getActivity(this, 0, preferenceIntent, PendingIntent.FLAG_CANCEL_CURRENT)) .setStyle(new NotificationCompat.BigTextStyle().bigText(content)); Notification notification = builder.build(); notification.flags = Notification.FLAG_AUTO_CANCEL; ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification); } } else if (ACTION_SCHEDULE_AUTO_BACKUP.equals(action)) { DailyAutoBackupScheduler.updateAutoBackupAlarms(this); } }
From source file:com.csipsimple.plugins.betamax.CallHandlerWeb.java
@Override public void onReceive(Context context, Intent intent) { if (Utils.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) { PendingIntent pendingIntent = null; // Extract infos from intent received String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); // Extract infos from settings SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String user = prefs.getString(CallHandlerConfig.KEY_TW_USER, ""); String pwd = prefs.getString(CallHandlerConfig.KEY_TW_PWD, ""); String nbr = prefs.getString(CallHandlerConfig.KEY_TW_NBR, ""); String provider = prefs.getString(CallHandlerConfig.KEY_TW_PROVIDER, ""); // We must handle that clean way cause when call just to // get the row in account list expect this to reply correctly if (!TextUtils.isEmpty(number) && !TextUtils.isEmpty(user) && !TextUtils.isEmpty(nbr) && !TextUtils.isEmpty(pwd) && !TextUtils.isEmpty(provider)) { // Build pending intent Intent i = new Intent(ACTION_DO_WEB_CALL); i.setClass(context, getClass()); i.putExtra(Intent.EXTRA_PHONE_NUMBER, number); pendingIntent = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); }// ww w. jav a 2s . c om // Build icon Bitmap bmp = Utils.getBitmapFromResource(context, R.drawable.icon_web); // Build the result for the row (label, icon, pending intent, and // excluded phone number) Bundle results = getResultExtras(true); if (pendingIntent != null) { results.putParcelable(Utils.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent); } // Text for the row String providerName = ""; Resources r = context.getResources(); if (!TextUtils.isEmpty(provider)) { String[] arr = r.getStringArray(R.array.provider_values); String[] arrEntries = r.getStringArray(R.array.provider_entries); int i = 0; for (String prov : arr) { if (prov.equalsIgnoreCase(provider)) { providerName = arrEntries[i]; break; } i++; } } results.putString(Intent.EXTRA_TITLE, providerName + " " + r.getString(R.string.web_callback)); Log.d(THIS_FILE, "icon is " + bmp); if (bmp != null) { results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, bmp); } // DO *NOT* exclude from next tel: intent cause we use a http method // results.putString(Intent.EXTRA_PHONE_NUMBER, number); } else if (ACTION_DO_WEB_CALL.equals(intent.getAction())) { // Extract infos from intent received String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); // Extract infos from settings SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String user = prefs.getString(CallHandlerConfig.KEY_TW_USER, ""); String pwd = prefs.getString(CallHandlerConfig.KEY_TW_PWD, ""); String nbr = prefs.getString(CallHandlerConfig.KEY_TW_NBR, ""); String provider = prefs.getString(CallHandlerConfig.KEY_TW_PROVIDER, ""); // params List<NameValuePair> params = new LinkedList<NameValuePair>(); params.add(new BasicNameValuePair("username", user)); params.add(new BasicNameValuePair("password", pwd)); params.add(new BasicNameValuePair("from", nbr)); params.add(new BasicNameValuePair("to", number)); String paramString = URLEncodedUtils.format(params, "utf-8"); String requestURL = "https://www." + provider + "/myaccount/makecall.php?" + paramString; HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(requestURL); // Create a response handler HttpResponse httpResponse; try { httpResponse = httpClient.execute(httpGet); Log.d(THIS_FILE, "response code is " + httpResponse.getStatusLine().getStatusCode()); if (httpResponse.getStatusLine().getStatusCode() == 200) { InputStreamReader isr = new InputStreamReader(httpResponse.getEntity().getContent()); BufferedReader br = new BufferedReader(isr); String line; String fullReply = ""; boolean foundSuccess = false; while ((line = br.readLine()) != null) { if (!TextUtils.isEmpty(line) && line.toLowerCase().contains("success")) { showToaster(context, "Success... wait a while you'll called back"); foundSuccess = true; break; } if (!TextUtils.isEmpty(line)) { fullReply = fullReply.concat(line); } } if (!foundSuccess) { showToaster(context, "Error : server error : " + fullReply); } } else { showToaster(context, "Error : invalid request " + httpResponse.getStatusLine().getStatusCode()); } } catch (ClientProtocolException e) { showToaster(context, "Error : " + e.getLocalizedMessage()); } catch (IOException e) { showToaster(context, "Error : " + e.getLocalizedMessage()); } } }
From source file:eu.inmite.apps.smsjizdenka.util.NotificationUtil.java
/** * Posts notification about new sms ticket. * * @param c context to post notification * @param t new ticket/*w ww . ja v a 2 s . c o m*/ */ public static void notifyTicket(Context c, Ticket t, boolean keepNotification) { String text; String ticker; int smallIcon; int largeIcon; int status; switch (TicketsAdapter.getValidityStatus(t.getStatus(), t.getValidTo())) { case TicketProvider.Tickets.STATUS_VALID: case TicketProvider.Tickets.STATUS_VALID_EXPIRING: text = c.getString(R.string.notif_valid_text, FormatUtil.formatDateTimeDifference(t.getValidTo())); ticker = c.getString(R.string.notif_valid_ticker); smallIcon = R.drawable.notification_small_ready; largeIcon = R.drawable.notification_big_ready; status = TicketProvider.Tickets.STATUS_VALID_EXPIRING; break; case TicketProvider.Tickets.STATUS_EXPIRING: case TicketProvider.Tickets.STATUS_EXPIRING_EXPIRED: text = c.getString(R.string.notif_expiring_text, FormatUtil.formatTime(t.getValidTo())); ticker = c.getString(R.string.notif_expiring_ticker); smallIcon = R.drawable.notification_small_warning; largeIcon = R.drawable.notification_big_warning; status = TicketProvider.Tickets.STATUS_EXPIRING_EXPIRED; break; case TicketProvider.Tickets.STATUS_EXPIRED: text = c.getString(R.string.notif_expired_text, FormatUtil.formatTime(t.getValidTo())); ticker = c.getString(R.string.notif_expired_ticker); smallIcon = R.drawable.notification_small_expired; largeIcon = R.drawable.notification_big_expired; status = TicketProvider.Tickets.STATUS_EXPIRED; break; default: return; } Intent intent = new Intent(c, WearableService.class); intent.setAction("sent_notification_to_wear"); intent.putExtra("ticket", t); intent.putExtra("status", status); c.startService(intent); Intent i = new Intent(c, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); i.putExtra(MainActivity.EXTRA_TICKET_ID, t.getId()); PendingIntent openIntent = PendingIntent.getActivity(c, t.getNotificationId(), i, PendingIntent.FLAG_CANCEL_CURRENT); Intent i2 = new Intent(c, MainActivity.class); i2.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); i2.putExtra(MainActivity.EXTRA_TICKET_ID, t.getId()); i2.putExtra(MainActivity.EXTRA_SHOW_SMS, true); PendingIntent showSmsIntent = PendingIntent.getActivity(c, t.getNotificationId() + 1000, i2, PendingIntent.FLAG_CANCEL_CURRENT); List<Action> actions = new ArrayList<Action>(); actions.add(new Action(R.drawable.notification_show_sms, R.string.notif_show_sms, showSmsIntent)); List<String> rows = new ArrayList<String>(); rows.add(text); rows.add(c.getString(R.string.tickets_valid_from) + ": " + FormatUtil.formatDateTime(t.getValidFrom())); rows.add(c.getString(R.string.tickets_code) + ": " + t.getHash()); fireNotification(c, t.getNotificationId(), openIntent, c.getString(R.string.application_name), text, rows, t.getCity(), ticker, smallIcon, largeIcon, actions, keepNotification); }
From source file:io.github.dector.rkpi.components.notifications.NotificationManager.java
/** * Create new instance/* w w w . j a v a2s. c o m*/ * * @param context application context */ public NotificationManager(Context context) { mContext = context; mManager = (android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.icon_bar; PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent playPauseIntent = PendingIntent.getBroadcast(context, 0, new Intent(Request.PLAYER_TOGGLE.encode()), PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent exitIntent = PendingIntent.getBroadcast(context, 0, new Intent(Request.EXIT.encode()), PendingIntent.FLAG_CANCEL_CURRENT); mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_layout); mRemoteViews.setOnClickPendingIntent(R.id.toggleButton, playPauseIntent); mRemoteViews.setOnClickPendingIntent(R.id.closeButton, exitIntent); mNotificationBuilder = new NotificationCompat.Builder(context).setSmallIcon(icon).setContent(mRemoteViews) .setContentIntent(contentIntent).setOngoing(true); }
From source file:cn.studyjams.s2.sj0119.NForget.AlarmReceiver.java
public void setAlarm(Context context, Calendar calendar, int ID) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification time Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using notification time mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, 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.devbd.cttd.hello_ct.PushPkg.GcmBroadcastReceiver.java
private void sendNotification(Bundle bundle) { String msg = bundle.getString("price"); System.out.println(">>>>>>>>>>FFFF " + bundle.toString()); // String from_name=bundle.getString("From_Name"); // String type=bundle.getString("Type"); // String params=bundle.getString("Params"); // NotificationDetails nd=new NotificationDetails(); // nd.setBody(msg); // nd.setFrom_email(from_email); // nd.setFrom_name(from_name); // nd.setFrom_image(from_image); // // w ww. j a v a2 s . co m mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); // if (msg != null) { Noti.msg = msg; PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, new Intent(ctx, Noti.class), PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx).setSmallIcon(R.mipmap.icon) .setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), R.mipmap.icon)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentTitle(ctx.getResources().getString(R.string.app_name)).setAutoCancel(true) .setContentText(Html.fromHtml(msg)) .setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(msg))); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } }
From source file:com.android.settings.service.AlarmService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { try {//from w ww . j a va2 s .c o m startAlarmSound(); } catch (Exception e) { // Do nothing } Bundle extras = intent.getExtras(); String names = extras.getString("number"); String title = getResources().getString(R.string.quiet_hours_alarm_dialog_title); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_quiethours); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setTicker(title) .setContentTitle(title).setContentText(names).setAutoCancel(false).setOngoing(true) .setSmallIcon(R.drawable.ic_quiethours).setLargeIcon(bm) .setStyle(new NotificationCompat.BigTextStyle() .bigText(names + getResources().getString(R.string.quiet_hours_alarm_message))); Intent alarmDialog = new Intent(); alarmDialog.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); alarmDialog.setClass(this, com.android.settings.service.BypassAlarm.class); alarmDialog.putExtra("number", names); alarmDialog.putExtra("norun", true); PendingIntent result = PendingIntent.getActivity(this, 0, alarmDialog, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(result); mManager.notify(NOTI_ID, builder.build()); return START_STICKY; }