List of usage examples for android.app PendingIntent getBroadcast
public static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java
public PendingIntent createPendingIntentForSchedule(String idString) { Intent intent = createIntentForSchedule(idString); return PendingIntent.getBroadcast(mContext, C.REQUEST_CODE_LOCALNOTIFICATION, intent, PendingIntent.FLAG_ONE_SHOT); }
From source file:com.google.android.apps.santatracker.cast.DataCastNotificationService.java
private void build(int titleId, int imageId) { // Main Content PendingIntent Intent contentIntent = new Intent(this, INTENT_ACTIVITY); // Disconnect PendingIntent Intent stopIntent = new Intent(ACTION_STOP); stopIntent.setPackage(getPackageName()); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0); // Media metadata String castingTo = getResources().getString(R.string.ccl_casting_to_device, mCastManager.getDeviceName()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(INTENT_ACTIVITY); stackBuilder.addNextIntent(contentIntent); PendingIntent contentPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_small).setContentTitle(getResources().getString(titleId)) .setContentText(castingTo).setContentIntent(contentPendingIntent) .setColor(ContextCompat.getColor(this, R.color.brandSantaTracker)) .addAction(R.drawable.ic_notification_disconnect_24dp, getString(R.string.ccl_disconnect), stopPendingIntent)/*from w w w .j a v a 2 s. co m*/ .setOngoing(true).setShowWhen(false).setVisibility(NotificationCompat.VISIBILITY_PUBLIC); mNotification = builder.build(); }
From source file:de.appplant.cordova.plugin.notification.Notification.java
/** * Cancel the local notification.//from w w w. ja v a 2s. c om * * Create an intent that looks similar, to the one that was registered * using schedule. Making sure the notification id in the action is the * same. Now we can search for such an intent using the 'getService' * method and cancel it. */ public void cancel() { Intent intent = new Intent(context, receiver).setAction(options.getId()); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); getAlarmMgr().cancel(pi); getNotMgr().cancel(options.getIdAsInt()); unpersist(); }
From source file:com.commontime.plugin.notification.notification.NotificationWrapper.java
/** * Cancel the local notification./*from w w w . j a v a 2s . c o m*/ * * Create an intent that looks similar, to the one that was registered * using schedule. Making sure the notification id in the action is the * same. Now we can search for such an intent using the 'getService' * method and cancel it. */ public void cancel() { Intent intent = new Intent(context, receiver).setAction(options.getIdStr()); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); getAlarmMgr().cancel(pi); getNotMgr().cancel(options.getId()); unpersist(); }
From source file:com.androzic.plugin.tracker.SMSReceiver.java
@Override public void onReceive(Context context, Intent intent) { String Sender = ""; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Log.e(TAG, "SMS received"); Bundle extras = intent.getExtras();//from w w w. j a v a2 s . c om if (extras == null) return; StringBuilder messageBuilder = new StringBuilder(); Object[] pdus = (Object[]) extras.get("pdus"); for (int i = 0; i < pdus.length; i++) { SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]); String text = msg.getMessageBody(); Sender = msg.getDisplayOriginatingAddress(); Log.w(TAG, "Sender: " + Sender); if (text == null) continue; messageBuilder.append(text); } String text = messageBuilder.toString(); boolean flexMode = prefs.getBoolean(context.getString(R.string.pref_tracker_use_flex_mode), context.getResources().getBoolean(R.bool.def_flex_mode)); Log.i(TAG, "SMS: " + text); Tracker tracker = new Tracker(); if (!parseXexunTK102(text, tracker) && !parseJointechJT600(text, tracker) && !parseTK102Clone1(text, tracker) && !(parseFlexMode(text, tracker) && flexMode)) return; if (tracker.message != null) { tracker.message = tracker.message.trim(); if ("".equals(tracker.message)) tracker.message = null; } tracker.sender = Sender; if (!"".equals(tracker.sender)) { // Save tracker data TrackerDataAccess dataAccess = new TrackerDataAccess(context); dataAccess.updateTracker(tracker); try { Application application = Application.getApplication(); tracker = dataAccess.getTracker(tracker.sender);//get latest positon of tracker application.sendTrackerOnMap(dataAccess, tracker); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } dataAccess.close(); context.sendBroadcast(new Intent(Application.TRACKER_DATE_RECEIVED_BROADCAST)); // Show notification boolean notifications = prefs.getBoolean(context.getString(R.string.pref_tracker_notifications), context.getResources().getBoolean(R.bool.def_notifications)); if (notifications) { Intent i = new Intent("com.androzic.COORDINATES_RECEIVED"); i.putExtra("title", tracker.message != null ? tracker.message : tracker.name); i.putExtra("sender", tracker.name); i.putExtra("origin", context.getApplicationContext().getPackageName()); i.putExtra("lat", tracker.latitude); i.putExtra("lon", tracker.longitude); String msg = context.getString(R.string.notif_text, tracker.name); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle(context.getString(R.string.app_name)); if (tracker.message != null) builder.setContentText(tracker.name + ": " + tracker.message); else builder.setContentText(msg); PendingIntent contentIntent = PendingIntent.getBroadcast(context, (int) tracker._id, i, PendingIntent.FLAG_ONE_SHOT); builder.setContentIntent(contentIntent); builder.setSmallIcon(R.drawable.ic_stat_tracker); builder.setTicker(msg); builder.setWhen(tracker.time); int defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND; boolean vibrate = prefs.getBoolean(context.getString(R.string.pref_tracker_vibrate), context.getResources().getBoolean(R.bool.def_vibrate)); if (vibrate) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); builder.setAutoCancel(true); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int) tracker._id, notification); } // Conceal SMS boolean concealsms = prefs.getBoolean(context.getString(R.string.pref_tracker_concealsms), context.getResources().getBoolean(R.bool.def_concealsms)); if (concealsms) abortBroadcast(); } }
From source file:com.meiste.greg.ptw.WidgetProvider.java
private PendingIntent getAlarmIntent(final Context context) { final Intent intent = new Intent(context, WidgetProvider.class); return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.deltadna.android.sdk.notifications.NotificationListenerService.java
/** * Creates a {@link android.support.v4.app.NotificationCompat.Builder} * whose built result will be posted on the {@link NotificationManager}. * * Implementations which call/*from ww w .j a v a 2s .c o m*/ * {@link NotificationCompat.Builder#setContentIntent(PendingIntent)} * or * {@link NotificationCompat.Builder#setDeleteIntent(PendingIntent)} * on the {@link NotificationCompat.Builder} and thus override the default * behaviour should notify the SDK that the push notification has been * opened or dismissed respectively. * * @param data the data from the message * * @return configured notification builder * * @see NotificationInteractionReceiver */ protected NotificationCompat.Builder createNotification(Bundle data) { final String title = getTitle(data); final String alert; if (data.containsKey(PLATFORM_ALERT)) { alert = data.getString(PLATFORM_ALERT); } else { Log.w(TAG, "Missing 'alert' key in message"); alert = "Missing 'alert' key"; } final NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(getIcon()) .setContentTitle(title).setContentText(alert).setAutoCancel(true); // to make the behaviour consistent with iOS on Unity final boolean backgrounded = !Utils.inForeground(this); if (!backgrounded) { Log.d(TAG, "Notifying SDK of notification opening"); DDNANotifications.recordNotificationOpened(data, false); } builder.setContentIntent( PendingIntent.getBroadcast(this, 0, new Intent(Actions.NOTIFICATION_OPENED).putExtra(DDNANotifications.EXTRA_PAYLOAD, data) .putExtra(DDNANotifications.EXTRA_LAUNCH, backgrounded), PendingIntent.FLAG_ONE_SHOT)); builder.setDeleteIntent(PendingIntent.getBroadcast(this, 0, new Intent(Actions.NOTIFICATION_DISMISSED).putExtra(DDNANotifications.EXTRA_PAYLOAD, data), PendingIntent.FLAG_ONE_SHOT)); return builder; }
From source file:com.javadog.cgeowear.WearService.java
/** * Starts service & watch app.//from w w w . j a v a 2s . c o m */ private void handleInit() { SharedPreferences userPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); //Register listener for INTENT_STOP events IntentFilter filter = new IntentFilter(INTENT_STOP); registerReceiver(intentReceiver, filter); //Register listener for when watch app closes IntentFilter localFilter = new IntentFilter(ListenerService.PATH_KILL_APP); LocalBroadcastManager.getInstance(this).registerReceiver(localReceiver, localFilter); //Show a persistent notification Intent stopServiceIntent = new Intent(INTENT_STOP); PendingIntent nIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, stopServiceIntent, 0); Notification notification = new NotificationCompat.Builder(getApplicationContext()).setOngoing(true) .setContentIntent(nIntent).setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getText(R.string.app_name)).setContentText(getText(R.string.notification_text)) .build(); //Specify how quickly we want to receive location updates locationRequest = LocationRequest.create().setInterval(LOCATION_UPDATE_INTERVAL) .setFastestInterval(LOCATION_UPDATE_MAX_INTERVAL) .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); //Start reading compass sensors if using phone compass useWatchCompass = userPrefs.getBoolean("pref_use_watch_compass", false); if (!useWatchCompass) { sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); magnetometer = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); sensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_NORMAL); } //Start service in foreground startForeground(R.string.app_name, notification); }
From source file:com.jmstudios.redmoon.receiver.AutomaticFilterChangeReceiver.java
public static void cancelPauseAlarm(Context context) { Intent commands = new Intent(context, AutomaticFilterChangeReceiver.class); commands.setData(Uri.parse("pauseIntent")); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, commands, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent);//from w w w . j a v a 2 s .c o m }
From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java
@Override protected void onPostExecute(JSONObject jsonObject) { if (jsonObject != null) { try {// w w w.j a v a2 s . c o m Context context = mContext.get(); if (context == null) { return; } AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); for (int x : mMap.keySet()) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_layout); double price = jsonObject.getJSONObject(mMap.get(x).replace("/", "_").toLowerCase(Locale.US)) .getDouble("last"); String priceString; if (price > 1) { priceString = (new DecimalFormat("#.##")).format(price); } else { priceString = String.valueOf(price); } views.setTextViewText(R.id.widgetCurrencyValue, priceString); views.setTextViewText(R.id.widgetPair, mMap.get(x)); String color = jsonObject.getJSONObject(mMap.get(x).replace("/", "_").toLowerCase(Locale.US)) .getString("color"); int colorValue = color.equals("green") ? Color.GREEN : Color.RED; views.setTextColor(R.id.widgetCurrencyValue, colorValue); Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); Bundle bundle = new Bundle(); bundle.putIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetProvider.class))); intent.putExtras(bundle); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.widgetContainer, pi); SimpleDateFormat df = new SimpleDateFormat("EEE HH:mm", Locale.US); Calendar calendar = Calendar.getInstance(); views.setTextViewText(R.id.widgetDate, df.format(calendar.getTime())); appWidgetManager.updateAppWidget(x, views); } } catch (JSONException e) { e.printStackTrace(); } } }