List of usage examples for android.app PendingIntent FLAG_UPDATE_CURRENT
int FLAG_UPDATE_CURRENT
To view the source code for android.app PendingIntent FLAG_UPDATE_CURRENT.
Click Source Link
From source file:com.android.mms.transaction.SendTransaction.java
public void run() { Log.d(MmsApp.TXN_TAG, "SendTransaction: run"); RateController rateCtlr = RateController.getInstance(); if (rateCtlr.isLimitSurpassed() && !rateCtlr.isAllowedByUser()) { Log.e(TAG, "Sending rate limit surpassed."); return;/*from w w w .j a v a 2s .c o m*/ } try { final PduPersister persister = PduPersister.getPduPersister(mContext); final SendReq sendReq = (SendReq) persister.load(mUri); if (sendReq == null) { Log.w(MmsApp.TXN_TAG, "Send req is null!"); return; } byte[] datas = new PduComposer(mContext, sendReq).make(); mPduFile = createPduFile(datas, SEND_REQ_NAME + mUri.getLastPathSegment()); if (mPduFile == null) { Log.w(MmsApp.TXN_TAG, "create pdu file req failed!"); return; } //Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED); //intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId); //intent.putExtra(TransactionBundle.URI, mUri.toString()); Log.d(MmsApp.TXN_TAG, "SendTransaction mUri:" + mUri); final Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED, mUri, mContext, MmsReceiver.class); intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId); PendingIntent sentIntent = PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Log.d(MmsApp.TXN_TAG, "send MMS with param, mUri = " + mUri + " mPdufile = " + mPduFile + ", subId = " + mSubId); Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, mPduFile); /// M: Add MmsService configure param @{ SmsManager.getSmsManagerForSubscriptionId(mSubId).sendMultimediaMessage(mContext, pduFileUri, null, MmsConfig.getMmsServiceConfig(), sentIntent); /// @} } catch (Throwable t) { Log.e(TAG, Log.getStackTraceString(t)); getState().setState(FAILED); getState().setContentUri(mUri); notifyObservers(); } }
From source file:alaindc.memenguage.RandomIntentService.java
private void sendNotification(long id_word) { String title = "Memenguage"; String description = "Do you remember?"; // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(getApplicationContext(), GuessActivity.class); notificationIntent.setAction(Constants.ACTION_GUESS_ACTIVITY); notificationIntent.putExtra(Constants.EXTRA_GUESS_IDWORD, id_word); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(MainActivity.class); // Push the content Intent onto the stack. stackBuilder.addNextIntentWithParentStack(notificationIntent); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // Define the notification settings. builder.setSmallIcon(R.drawable.icon) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo)).setColor(Color.RED) .setContentTitle(title).setContentText(description).setDefaults(Notification.DEFAULT_ALL) .setContentIntent(notificationPendingIntent); try {/* ww w .j a v a 2 s .c o m*/ String urisound = PreferenceManager.getDefaultSharedPreferences(this).getString("sound_notifications", ""); builder.setSound(Uri.parse(urisound)); } catch (Exception e) { Log.d("RandomIntentService", "Uri sound notification empty or wrong"); } try { Boolean vibrate = PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("vibrate_notifications", false); if (vibrate) builder.setVibrate(new long[] { 1000, 1000 }); } catch (Exception e) { Log.d("RandomIntentService", "Vibrate notification wrong"); } builder.setDefaults(0); // Dismiss notification once the user touches it. builder.setAutoCancel(true); // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(Constants.ID_NOTIFICATION_RANDOM_WORD, builder.build()); }
From source file:com.google.android.gcm.demo.app.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*w w w . j a va 2s . c o m*/ private static void generateNotification(Context context, String message, String data) { int icon = R.drawable.ic_stat_gcm; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(0); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, DemoActivity.class); notificationIntent.putExtra(CommonUtilities.EXTRA_TEAM_IN_JSON, data); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags = Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.achep.acdisplay.App.java
@Override public void onCreate() { mAccessManager = new AccessManager(this); AppHeap.getInstance().init(this); Config.getInstance().init(this); Blacklist.getInstance().init(this); SmileyParser.init(this); // Init the main notification listener. NotificationPresenter.getInstance()//from w ww.j av a2 s . com .setOnNotificationPostedListener(Config.getInstance().isEnabled() ? Presenter.getInstance() : null); super.onCreate(); // Check the main switch. String divider = getString(R.string.settings_multi_list_divider); Config config = Config.getInstance(); if (config.isEnabled()) { StringBuilder sb = new StringBuilder(); boolean foundAny = false; PermissionGroup pg = getAccessManager().getMasterPermissions(); for (Permission permission : pg.permissions) { if (!permission.isActive()) { if (foundAny) { sb.append(divider); } else foundAny = true; sb.append(getString(permission.getTitleResource())); } } if (foundAny) { String list = sb.toString(); list = list.charAt(0) + list.substring(1).toLowerCase(); ConfigBase.Option option = config.getOption(Config.KEY_ENABLED); option.write(config, this, false, null); final int id = App.ID_NOTIFY_APP_AUTO_DISABLED; PendingIntent pendingIntent = PendingIntent.getActivity(this, id, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(getString(R.string.permissions_auto_disabled)).setSummaryText(list); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.permissions_auto_disabled)) .setContentIntent(pendingIntent).setLargeIcon(largeIcon) .setSmallIcon(R.drawable.stat_acdisplay).setAutoCancel(true).setStyle(bts) .setPriority(Notification.PRIORITY_HIGH).setColor(App.ACCENT_COLOR); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(id, builder.build()); } } // Check the keyguard (without the notification). if (config.isKeyguardEnabled() && !getAccessManager().getKeyguardPermissions().isActive()) { ConfigBase.Option option = config.getOption(Config.KEY_KEYGUARD); option.write(config, this, false, null); } // Launch keyguard and (or) active mode on // app launch. KeyguardService.handleState(this); ActiveModeService.handleState(this); SensorsDumpService.handleState(this); }
From source file:cat.wuyingren.whatsannoy.utils.SystemUtils.java
public static int createScheduleNotification(Context context, Schedule s) { Log.w("UTILS", "createScheduleNotification()"); ScheduleDataSource dataSource;//from w ww . j ava 2s. c om dataSource = new ScheduleDataSource(context); dataSource.open(); // Random r = new Random(); int mId = 0;// r.nextInt(); //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String uri = s.getRingtone(); // prefs.getString("pref_general_sound_key", ""); Uri ringtone = Uri.parse(uri); if (uri == "") { // isEmpty() is not available on API 7 ringtone = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(context.getResources().getString(R.string.app_name)) .setContentText(context.getResources().getString(R.string.notification)); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MainActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.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); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mBuilder.setSound(ringtone); //mBuilder.setWhen(s.getDate()); mNotificationManager.notify(mId, mBuilder.build()); s.setIsEnabled(false); dataSource.updateSchedule(context, s); dataSource.close(); return mId; }
From source file:com.adkdevelopment.earthquakesurvival.ui.geofence.GeofenceService.java
/** * Sends a notification to the phone// w w w . ja va 2 s . c om * @param notificationDetails String with details to show in the notification */ private void sendNotification(List<String> notificationDetails) { Context context = getBaseContext(); // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(context, DetailActivity.class); notificationIntent.putStringArrayListExtra(Feature.GEOFENCE, (ArrayList<String>) notificationDetails); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(PagerActivity.class); // Push the content Intent onto the stack. stackBuilder.addNextIntent(notificationIntent); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); Bitmap largeIcon = null; try { largeIcon = Picasso.with(context).load(R.mipmap.ic_launcher).get(); } catch (IOException e) { Log.e(TAG, "e:" + e); } // Define the notification settings. builder.setAutoCancel(true).setSmallIcon(R.mipmap.ic_launcher).setDefaults(Notification.DEFAULT_ALL) .setLargeIcon(largeIcon).setColor(Color.RED).setTicker(getString(R.string.geofence_notification)) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.geofence_notification_text)) .setContentIntent(notificationPendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText( notificationDetails.get(0) + "\n" + getString(R.string.geofence_notification_text))) .setGroup(EarthquakeObject.NOTIFICATION_GROUP); // Get an instance of the Notification manager NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context); // Issue the notification mNotificationManager.notify(EarthquakeObject.NOTIFICATION_ID_1, builder.build()); }
From source file:com.adkdevelopment.rssreader.data.services.FetchJobService.java
/** * Raises a notification each day on news update. *//*from w ww. j a v a2 s. co m*/ private void sendNotification() { PrefsManager prefsManager = new PrefsManager(getBaseContext()); Context context = getApplicationContext(); final String NOTIFICATION_GROUP = "notif_group"; final int NOTIFICATION_ID_1 = 101; if (prefsManager.receiveNotifications()) { //checking the last update and notify if it's the first of the day if (System.currentTimeMillis() - prefsManager.getLastNotification() >= DateUtils.DAY_IN_MILLIS) { Intent intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, NOTIFICATION_ID_1, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true) .setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.articles_notification)) .setContentIntent(pendingIntent).setSmallIcon(R.drawable.logo_title) .setTicker(context.getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle() .bigText(context.getString(R.string.articles_notification))) .setGroup(NOTIFICATION_GROUP).setGroupSummary(true); NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context); managerCompat.notify(NOTIFICATION_ID_1, builder.build()); prefsManager.setLastNotification(); } } }
From source file:com.bullmobi.message.App.java
@Override public void onCreate() { mAccessManager = new AccessManager(this); AppHeap.getInstance().init(this); Config.getInstance().init(this); Blacklist.getInstance().init(this); SmileyParser.init(this); // Init the main notification listener. NotificationPresenter.getInstance()/*w ww . j av a2 s. co m*/ .setOnNotificationPostedListener(Config.getInstance().isEnabled() ? Presenter.getInstance() : null); super.onCreate(); // Check the main switch. String divider = getString(R.string.settings_multi_list_divider); Config config = Config.getInstance(); if (config.isEnabled()) { StringBuilder sb = new StringBuilder(); boolean foundAny = false; PermissionGroup pg = getAccessManager().getMasterPermissions(); for (Permission permission : pg.permissions) { if (!permission.isActive()) { if (foundAny) { sb.append(divider); } else foundAny = true; sb.append(getString(permission.getTitleResource())); } } if (foundAny) { String list = sb.toString(); list = list.charAt(0) + list.substring(1).toLowerCase(); ConfigBase.Option option = config.getOption(Config.KEY_ENABLED); option.write(config, this, false, null); final int id = App.ID_NOTIFY_APP_AUTO_DISABLED; PendingIntent pendingIntent = PendingIntent.getActivity(this, id, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(getString(R.string.permissions_auto_disabled)).setSummaryText(list); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.permissions_auto_disabled)) .setContentIntent(pendingIntent).setLargeIcon(largeIcon) .setSmallIcon(R.drawable.stat_easynotification).setAutoCancel(true).setStyle(bts) .setPriority(Notification.PRIORITY_HIGH).setColor(App.ACCENT_COLOR); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(id, builder.build()); } } // Check the keyguard (without the notification). if (config.isKeyguardEnabled() && !getAccessManager().getKeyguardPermissions().isActive()) { ConfigBase.Option option = config.getOption(Config.KEY_KEYGUARD); option.write(config, this, false, null); } // Launch keyguard and (or) active mode on // app launch. KeyguardService.handleState(this); ActiveModeService.handleState(this); SensorsDumpService.handleState(this); }
From source file:com.amaze.filemanager.asynchronous.services.ExtractService.java
@Override public int onStartCommand(Intent intent, int flags, final int startId) { String file = intent.getStringExtra(KEY_PATH_ZIP); String extractPath = intent.getStringExtra(KEY_PATH_EXTRACT); String[] entries = intent.getStringArrayExtra(KEY_ENTRIES_ZIP); mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); accentColor = ((AppConfig) getApplication()).getUtilsProvider().getColorPreference() .getCurrentUserColorPreferences(this, sharedPreferences).accent; Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); customSmallContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_small); customBigContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_big); Intent stopIntent = new Intent(TAG_BROADCAST_EXTRACT_CANCEL); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context, 1234, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_zip_box_grey600_36dp, getString(R.string.stop_ftp), stopPendingIntent); mBuilder = new NotificationCompat.Builder(context, NotificationConstants.CHANNEL_NORMAL_ID); mBuilder.setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_zip_box_grey600_36dp) .setContentIntent(pendingIntent).setCustomContentView(customSmallContentViews) .setCustomBigContentView(customBigContentViews).setCustomHeadsUpContentView(customSmallContentViews) .setStyle(new NotificationCompat.DecoratedCustomViewStyle()).addAction(action).setOngoing(true) .setColor(accentColor);/*from ww w . j av a2s .c om*/ NotificationConstants.setMetadata(getApplicationContext(), mBuilder, NotificationConstants.TYPE_NORMAL); startForeground(NotificationConstants.EXTRACT_ID, mBuilder.build()); initNotificationViews(); long totalSize = getTotalSize(file); progressHandler.setSourceSize(1); progressHandler.setTotalSize(totalSize); progressHandler.setProgressListener((speed) -> publishResults(speed, false, false)); super.onStartCommand(intent, flags, startId); super.progressHalted(); new DoWork(this, progressHandler, file, extractPath, entries).execute(); return START_STICKY; }
From source file:com.fanfou.app.opensource.service.DownloadService.java
private final static PendingIntent getPendingIntent(final Context context) { final Intent intent = new Intent(context, DownloadService.class); intent.putExtra(Constants.EXTRA_TYPE, DownloadService.TYPE_CHECK); final PendingIntent pi = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); return pi;//from w w w . j a v a2 s .c o m }