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.dudu.aios.ui.activity.MainRecordActivity.java
private void cancelWeatherAlarm() { Intent intent = new Intent(this, WeatherAlarmReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, 0); mAlarmManager.cancel(pi);/*w w w. j ava2 s.c o m*/ }
From source file:com.google.android.marvin.mytalkback.TalkBackService.java
/** * Suspends TalkBack and Explore by Touch. *//*from w w w . jav a2 s . co m*/ private void suspendTalkBack() { if (!isServiceActive()) { LogUtils.log(this, Log.ERROR, "Attempted to suspend TalkBack while already suspended."); return; } mFeedbackController.playAuditory(R.id.sounds_paused_feedback); if (SUPPORTS_TOUCH_PREF) { requestTouchExploration(false); } if (mCursorController != null) { mCursorController.clearCursor(); } final IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_RESUME_FEEDBACK); filter.addAction(Intent.ACTION_SCREEN_ON); registerReceiver(mSuspendedReceiver, filter, PERMISSION_TALKBACK, null); // Suspending infrastructure sets sIsTalkBackSuspended to true. suspendInfrastructure(); final Intent resumeIntent = new Intent(ACTION_RESUME_FEEDBACK); final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, resumeIntent, 0); final Notification notification = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.notification_title_talkback_suspended)) .setContentText(getString(R.string.notification_message_talkback_suspended)) .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.ic_stat_info) .setContentIntent(pendingIntent).setOngoing(true).setWhen(0).build(); startForeground(R.id.notification_suspended, notification); }
From source file:com.mobiperf.MeasurementScheduler.java
/** Set the interval for checkin in seconds */ public synchronized void setCheckinInterval(long interval) { this.checkinIntervalSec = Math.max(Config.MIN_CHECKIN_INTERVAL_SEC, interval); // the new checkin schedule will start in PAUSE_BETWEEN_CHECKIN_CHANGE_MSEC seconds checkinIntentSender = PendingIntent.getBroadcast(this, 0, new UpdateIntent("", UpdateIntent.CHECKIN_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + Config.PAUSE_BETWEEN_CHECKIN_CHANGE_MSEC, checkinIntervalSec * 1000, checkinIntentSender);//w w w . j a v a 2s .c om Logger.i("Setting checkin interval to " + interval + " seconds"); }
From source file:com.android.nfc.beam.BeamTransferManager.java
PendingIntent buildCancelIntent() { Intent intent = new Intent(BeamStatusReceiver.ACTION_CANCEL_HANDOVER_TRANSFER); intent.putExtra(BeamStatusReceiver.EXTRA_ADDRESS, mRemoteDevice.getAddress()); intent.putExtra(BeamStatusReceiver.EXTRA_INCOMING, mIncoming ? BeamStatusReceiver.DIRECTION_INCOMING : BeamStatusReceiver.DIRECTION_OUTGOING); PendingIntent pi = PendingIntent.getBroadcast(mContext, mTransferId, intent, PendingIntent.FLAG_ONE_SHOT); return pi;/*from w w w . jav a 2 s. c o m*/ }
From source file:com.google.android.marvin.screenspeak.ScreenSpeakService.java
/** * Suspends ScreenSpeak and Explore by Touch. *///from w w w.ja v a 2s . c o m public void suspendScreenSpeak() { if (!isServiceActive()) { if (LogUtils.LOG_LEVEL <= Log.ERROR) { Log.e(LOGTAG, "Attempted to suspend ScreenSpeak while already suspended."); } return; } SharedPreferencesUtils.storeBooleanAsync(mPrefs, getString(R.string.pref_suspended), true); mFeedbackController.playAuditory(R.raw.paused_feedback); if (mSupportsTouchScreen) { requestTouchExploration(false); } if (mCursorController != null) { try { mCursorController.clearCursor(); } catch (SecurityException e) { if (LogUtils.LOG_LEVEL >= Log.ERROR) { Log.e(LOGTAG, "Unable to clear cursor"); } } } final IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_RESUME_FEEDBACK); filter.addAction(Intent.ACTION_SCREEN_ON); registerReceiver(mSuspendedReceiver, filter, PERMISSION_SCREENSPEAK, null); // Suspending infrastructure sets sIsScreenSpeakSuspended to true. suspendInfrastructure(); final Intent resumeIntent = new Intent(ACTION_RESUME_FEEDBACK); final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, resumeIntent, 0); final Notification notification = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.notification_title_screenspeak_suspended)) .setContentText(getString(R.string.notification_message_screenspeak_suspended)) .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.ic_stat_info) .setContentIntent(pendingIntent).setOngoing(true).setWhen(0).build(); startForeground(R.id.notification_suspended, notification); mSpeechController.speak(getString(R.string.screenspeak_suspended), SpeechController.QUEUE_MODE_UNINTERRUPTIBLE, 0, null); }
From source file:edu.missouri.bas.service.SensorService.java
public void startSound() { Intent scheduleTriggerSound = new Intent(SensorService.ACTION_TRIGGER_SOUND); Intent scheduleTriggerSound2 = new Intent(SensorService.ACTION_TRIGGER_SOUND2); triggerSound = PendingIntent.getBroadcast(serviceContext, 0, scheduleTriggerSound, 0); triggerSound2 = PendingIntent.getBroadcast(serviceContext, 0, scheduleTriggerSound2, 0); mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000, triggerSound); mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000 * 20, triggerSound2);//from w ww . j ava 2 s . co m }
From source file:com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService.java
/** * Returns the {@link NotificationCompat.Action} for toggling play/pause/stop of the currently * playing item./*from w w w .j a v a 2 s . c o m*/ */ protected NotificationCompat.Action getPlayPauseAction(MediaInfo info, boolean isPlaying) { int pauseOrStopResourceId; if (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) { pauseOrStopResourceId = R.drawable.ic_notification_stop_48dp; } else { pauseOrStopResourceId = R.drawable.ic_notification_pause_48dp; } int pauseOrPlayTextResourceId = isPlaying ? R.string.ccl_pause : R.string.ccl_play; int pauseOrPlayResourceId = isPlaying ? pauseOrStopResourceId : R.drawable.ic_notification_play_48dp; Intent intent = new Intent(ACTION_TOGGLE_PLAYBACK); intent.setPackage(getPackageName()); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); return new NotificationCompat.Action.Builder(pauseOrPlayResourceId, getString(pauseOrPlayTextResourceId), pendingIntent).build(); }
From source file:com.github.mjdev.libaums.usbfileman.MainActivity.java
/** * Searches for connected mass storage devices, and initializes them if it * could find some./* w ww . j a va 2 s. c om*/ */ private void discoverDevice() { UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE); UsbMassStorageDevice[] devices = UsbMassStorageDevice.getMassStorageDevices(this); if (devices.length == 0) { Log.w(TAG, "no device found!"); android.support.v7.app.ActionBar actionBar = getSupportActionBar(); actionBar.setTitle("No device"); listView.setAdapter(null); return; } // we only use the first device device = devices[0]; UsbDevice usbDevice = (UsbDevice) getIntent().getParcelableExtra(UsbManager.EXTRA_DEVICE); if (usbDevice != null && usbManager.hasPermission(usbDevice)) { Log.d(TAG, "received usb device via intent"); // requesting permission is not needed in this case setupDevice(); } else { // first request permission from user to communicate with the // underlying // UsbDevice PendingIntent permissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); usbManager.requestPermission(device.getUsbDevice(), permissionIntent); } }
From source file:com.android.mms.transaction.MessagingNotification.java
public static void blockingUpdateNewIccMessageIndicator(Context context, String address, String message, int subId, long timeMillis) { final Notification.Builder noti = new Notification.Builder(context).setWhen(timeMillis); Contact contact = Contact.get(address, false); NotificationInfo info = getNewIccMessageNotificationInfo(context, true /* isSms */, address, message, null /* subject */, subId, timeMillis, null /* attachmentBitmap */, contact, WorkingMessage.TEXT); noti.setSmallIcon(R.drawable.stat_notify_sms); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); // Update the notification. PendingIntent pendingIntent;//from www . j a va 2 s .c o m if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { pendingIntent = PendingIntent.getActivity(context, 0, info.mClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); } else { // Use requestCode to avoid updating all intents of previous notifications pendingIntent = PendingIntent.getActivity(context, ICC_NOTIFICATION_ID_BASE + subId, info.mClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); } String title = info.mTitle; noti.setContentTitle(title).setContentIntent(pendingIntent) //taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)) .setCategory(Notification.CATEGORY_MESSAGE).setPriority(Notification.PRIORITY_DEFAULT); int defaults = 0; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); boolean vibrate = false; if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE)) { // The most recent change to the vibrate preference is to store a boolean // value in NOTIFICATION_VIBRATE. If prefs contain that preference, use that // first. vibrate = sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_VIBRATE, false); } else if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN)) { // This is to support the pre-JellyBean MR1.1 version of vibrate preferences // when vibrate was a tri-state setting. As soon as the user opens the Messaging // app's settings, it will migrate this setting from NOTIFICATION_VIBRATE_WHEN // to the boolean value stored in NOTIFICATION_VIBRATE. String vibrateWhen = sp.getString(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN, null); vibrate = "always".equals(vibrateWhen); } if (vibrate) { defaults |= Notification.DEFAULT_VIBRATE; } String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null); noti.setSound(TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr)); Log.d(TAG, "blockingUpdateNewIccMessageIndicator: adding sound to the notification"); defaults |= Notification.DEFAULT_LIGHTS; noti.setDefaults(defaults); // set up delete intent noti.setDeleteIntent(PendingIntent.getBroadcast(context, 0, sNotificationOnDeleteIntent, 0)); final Notification notification; // This sets the text for the collapsed form: noti.setContentText(info.formatBigMessage(context)); if (info.mAttachmentBitmap != null) { // The message has a picture, show that notification = new Notification.BigPictureStyle(noti).bigPicture(info.mAttachmentBitmap) // This sets the text for the expanded picture form: .setSummaryText(info.formatPictureMessage(context)).build(); } else { // Show a single notification -- big style with the text of the whole message notification = new Notification.BigTextStyle(noti).bigText(info.formatBigMessage(context)).build(); } notifyUserIfFullScreen(context, title); nm.notify(ICC_NOTIFICATION_ID_BASE + subId, notification); }
From source file:com.android.deskclock.timer.TimerReceiver.java
private void showTimesUpNotification(final Context context, TimerObj timerObj) { // Content Intent. When clicked will show the timer full screen PendingIntent contentIntent = PendingIntent.getActivity(context, timerObj.mTimerId, new Intent(context, TimerAlertFullScreen.class).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId),/*w ww . ja va 2s .com*/ PendingIntent.FLAG_UPDATE_CURRENT); // Add one minute action button PendingIntent addOneMinuteAction = PendingIntent.getBroadcast(context, timerObj.mTimerId, new Intent(Timers.NOTIF_TIMES_UP_PLUS_ONE).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId), PendingIntent.FLAG_UPDATE_CURRENT); // Add stop/done action button PendingIntent stopIntent = PendingIntent.getBroadcast(context, timerObj.mTimerId, new Intent(Timers.NOTIF_TIMES_UP_STOP).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId), PendingIntent.FLAG_UPDATE_CURRENT); // Notification creation final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentIntent(contentIntent) .addAction(R.drawable.ic_add_24dp, context.getResources().getString(R.string.timer_plus_1_min), addOneMinuteAction) .addAction( timerObj.getDeleteAfterUse() ? android.R.drawable.ic_menu_close_clear_cancel : R.drawable.ic_stop_24dp, timerObj.getDeleteAfterUse() ? context.getResources().getString(R.string.timer_done) : context.getResources().getString(R.string.timer_stop), stopIntent) .setContentTitle(timerObj.getLabelOrDefault(context)) .setContentText(context.getResources().getString(R.string.timer_times_up)) .setSmallIcon(R.drawable.stat_notify_timer).setOngoing(true).setAutoCancel(false) .setPriority(NotificationCompat.PRIORITY_MAX).setDefaults(NotificationCompat.DEFAULT_LIGHTS) .setWhen(0); // Send the notification using the timer's id to identify the // correct notification NotificationManagerCompat.from(context).notify(timerObj.mTimerId, builder.build()); if (Timers.LOGGING) { Log.v(TAG, "Setting times-up notification for " + timerObj.getLabelOrDefault(context) + " #" + timerObj.mTimerId); } }