List of usage examples for android.app PendingIntent getService
public static PendingIntent getService(Context context, int requestCode, @NonNull Intent intent, @Flags int flags)
From source file:com.kubotaku.android.code4kyoto5374.util.AlarmService.java
/** * ?//from ww w . j a va 2 s . c om * * @param context * @param garbageType ?? */ public static void cancelAlarm(Context context, final int garbageType) { final Intent intent = createIntent(context, garbageType); final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(pendingIntent); }
From source file:org.andicar.service.UpdateCheckService.java
private void setNextRun() { Calendar cal = Calendar.getInstance(); if (cal.get(Calendar.HOUR_OF_DAY) >= 18) cal.add(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 20); cal.set(Calendar.MINUTE, 0);//from w w w. j av a 2s.co m Intent i = new Intent(this, UpdateCheckService.class); PendingIntent pIntent = PendingIntent.getService(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC, cal.getTimeInMillis(), pIntent); }
From source file:com.google.android.apps.santatracker.WearNotificationService.java
/** * Builds a simple notification on the wearable. *//* w w w .jav a 2 s.com*/ private void buildTakeoffNotification(String content) { Log.v(TAG, "buildTakeoffNotification: " + content); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentText(content) .setSmallIcon(R.drawable.ic_launcher); // TODO workaround for bug for always displaying notifications builder.setContentTitle(""); Bitmap largeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.santa_notification_background); builder.setLargeIcon(largeIcon); //We want to know when the notification is dismissed, so we can dismiss it on the phone. Intent dismissIntent = new Intent(NotificationConstants.ACTION_DISMISS); dismissIntent.putExtra(NotificationConstants.KEY_NOTIFICATION_ID, NotificationConstants.NOTIFICATION_ID); PendingIntent pendingIntent = PendingIntent.getService(this, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setDeleteIntent(pendingIntent); //Post the notification. NotificationManagerCompat.from(this).notify(NotificationConstants.NOTIFICATION_ID, builder.build()); }
From source file:luan.com.flippit.GcmIntentService.java
private void extraDialog(String msg, String extraFilename, String extraType) { Log.i(MyActivity.TAG, getClass().getName() + ": " + "Extra notification."); String url = msg;//from w ww . j a v a 2s. c om Intent intentWeb = new Intent(Intent.ACTION_VIEW); intentWeb.setData(Uri.parse(url)); PendingIntent pendingWeb = PendingIntent.getActivity(mContext, 0, intentWeb, PendingIntent.FLAG_UPDATE_CURRENT); Intent intentCopy = new Intent(mContext, CopyService.class); intentCopy.putExtra("msg", msg); PendingIntent pendingCopy = PendingIntent.getService(mContext, 0, intentCopy, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = GeneralUtilities.createNotificationBuilder(mContext); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setTicker("Rich message") .addAction(R.drawable.send_white, "Open", pendingWeb) .addAction(R.drawable.copy_white, "Copy", pendingCopy).setContentText("Rich message"); mNotificationManager.cancel(1); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); UpdateHistory updateHistory = new UpdateHistory(); updateHistory.updateHistory(mContext); }
From source file:alaindc.crowdroid.SensorsIntentService.java
@Override protected void onHandleIntent(Intent intent) { if (intent != null) { final String action = intent.getAction(); if (action.equals(Constants.INTENT_START_SENSORS)) { // Init throughput taken SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean(Constants.THROUGHPUT_TAKEN, false); editor.commit();/*from w w w. j a v a 2s . c om*/ // Configure sensors and eventlistener mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE); List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensorList) { if (Constants.isInMonitoredSensors(sensor.getType())) mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } // TODO STUB: Comment this in release for (int type : Constants.STUBBED_MONITORED_SENSORS) { stub_onSensorChanged(type); } } if (action.equals(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE)) { // Configure amplitude and start TEST amplitudeTask = new GetAmplitudeTask(this); amplitudeTask.getData(); } if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_AMBIENT_TEMPERATURE)) { stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1)); } if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_PRESSURE)) { stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1)); } if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_RELATIVE_HUMIDITY)) { stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1)); } if (action.equals(Constants.INTENT_RECEIVED_AMPLITUDE)) { double amplitude = intent.getDoubleExtra(Constants.EXTRA_AMPLITUDE, -1); if (amplitude > 0) { SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString(Constants.PREF_SENSOR_ + Constants.TYPE_AMPLITUDE, Double.toString(amplitude)); editor.commit(); // Update view Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS); senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA, "Sensor " + Constants.getNameOfSensor(Constants.TYPE_AMPLITUDE) + " value: " + Double.toString(amplitude)); LocalBroadcastManager.getInstance(this).sendBroadcast(senseintent); } int index = Constants.getIndexAlarmForSensor(Constants.TYPE_AMPLITUDE); // Set the alarms for next sensing of amplitude alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); Intent intentAlarm = new Intent(getApplicationContext(), SensorsIntentService.class); intentAlarm.setAction(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE); alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0); // TIMEOUT for another monitoring of audio int seconds = 30; // TODO: De-hardcode this alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000, alarmIntent); } } }
From source file:com.conferenceengineer.android.iosched.service.SessionAlarmService.java
private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID);/*from w ww. j av a 2 s . c o m*/ final long currentTime = UIUtils.getCurrentTime(this); // If the session is already started, do not schedule system notification. if (currentTime > sessionStart) return; // By default, sets alarm to go off at 10 minutes before session start time. If alarm // offset is provided, alarm is set to go off by that much time from now. long alarmTime; if (alarmOffset == UNDEFINED_ALARM_OFFSET) { alarmTime = sessionStart - MILLI_TEN_MINUTES; } else { alarmTime = currentTime + alarmOffset; } final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class); // Setting data to ensure intent's uniqueness for different session start times. notifIntent.setData(new Uri.Builder().authority("com.conferenceengineer.android.iosched") .path(String.valueOf(sessionStart)).build()); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd); notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset); PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Schedule an alarm to be fired to notify user of added sessions are about to begin. am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); }
From source file:info.papdt.blacklight.support.Utility.java
public static void stopServiceAlarm(Context context, Class<?> service) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, service); PendingIntent p = PendingIntent.getService(context, REQUEST_CODE, i, PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(p);//from w w w . j a v a 2 s .c o m }
From source file:de.schildbach.wallet.service.InactivityNotificationService.java
private void handleMaybeShowNotification() { final Coin estimatedBalance = wallet.getBalance(BalanceType.ESTIMATED_SPENDABLE); if (estimatedBalance.isPositive()) { log.info("detected balance, showing inactivity notification"); final Coin availableBalance = wallet.getBalance(BalanceType.AVAILABLE_SPENDABLE); final boolean canDonate = Constants.DONATION_ADDRESS != null && availableBalance.isPositive(); final MonetaryFormat btcFormat = config.getFormat(); final String title = getString(R.string.notification_inactivity_title); final StringBuilder text = new StringBuilder( getString(R.string.notification_inactivity_message, btcFormat.format(estimatedBalance))); if (canDonate) text.append("\n\n").append(getString(R.string.notification_inactivity_message_donate)); final Intent dismissIntent = new Intent(this, InactivityNotificationService.class); dismissIntent.setAction(ACTION_DISMISS); final Intent dismissForeverIntent = new Intent(this, InactivityNotificationService.class); dismissForeverIntent.setAction(ACTION_DISMISS_FOREVER); final Intent donateIntent = new Intent(this, InactivityNotificationService.class); donateIntent.setAction(ACTION_DONATE); final NotificationCompat.Builder notification = new NotificationCompat.Builder(this); notification.setStyle(new NotificationCompat.BigTextStyle().bigText(text)); notification.setSmallIcon(R.drawable.stat_notify_received_24dp); notification.setContentTitle(title); notification.setContentText(text); notification.setContentIntent(/* w ww . j av a2 s . c o m*/ PendingIntent.getActivity(this, 0, new Intent(this, WalletActivity.class), 0)); notification.setAutoCancel(true); if (!canDonate) notification.addAction(new NotificationCompat.Action.Builder(0, getString(R.string.notification_inactivity_action_dismiss), PendingIntent.getService(this, 0, dismissIntent, 0)).build()); notification.addAction(new NotificationCompat.Action.Builder(0, getString(R.string.notification_inactivity_action_dismiss_forever), PendingIntent.getService(this, 0, dismissForeverIntent, 0)).build()); if (canDonate) notification.addAction( new NotificationCompat.Action.Builder(0, getString(R.string.wallet_options_donate), PendingIntent.getService(this, 0, donateIntent, 0)).build()); nm.notify(Constants.NOTIFICATION_ID_INACTIVITY, notification.build()); } }
From source file:com.example.ireviewr.MainActivity.java
private void setUpReceiver() { sync = new SyncReceiver(); // Retrieve a PendingIntent that will perform a broadcast Intent alarmIntent = new Intent(this, SyncService.class); pendingIntent = PendingIntent.getService(this, 0, alarmIntent, 0); manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); consultPreferences();/*from ww w. j ava 2s .c o m*/ }
From source file:com.stasbar.knowyourself.alarms.AlarmNotifications.java
public static void showHighPriorityNotification(Context context, AlarmInstance instance) { LogUtils.v("Displaying high priority notification for alarm instance: " + instance.mId); NotificationCompat.Builder notification = new NotificationCompat.Builder(context).setShowWhen(false) .setContentTitle(context.getString(R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */)) .setColor(ContextCompat.getColor(context, R.color.default_background)) .setSmallIcon(R.drawable.stat_notify_alarm).setAutoCancel(false).setSortKey(createSortKey(instance)) .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setLocalOnly(true); if (Utils.isNOrLater()) { notification.setGroup(UPCOMING_GROUP_KEY); }/*from w w w . j a v a 2s . co m*/ // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.PREDISMISSED_STATE); notification.addAction(R.drawable.ic_alarm_off_24dp, context.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getService(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm Intent viewAlarmIntent = createViewAlarmIntent(context, instance); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); nm.notify(instance.hashCode(), notification.build()); updateAlarmGroupNotification(context); }