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.andreadec.musicplayer.PodcastEpisodeDownloaderService.java
@Override public void onCreate() { super.onCreate(); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setSmallIcon(android.R.drawable.stat_sys_download); notificationBuilder.setOngoing(true); notificationBuilder.setProgress(100, 0, true); stopDownloadPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(STOP_DOWNLOAD_INTENT), 0); notificationBuilder.addAction(R.drawable.cancel, getResources().getString(R.string.stopDownload), stopDownloadPendingIntent);/*from www. j av a 2 s .co m*/ }
From source file:com.devnoobs.bmr.Powiadomienia.java
public void setAlarm(int h, int m) { Calendar calendar = przygotujCzas(h, m); AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(S); PendingIntent pi = PendingIntent.getBroadcast(c, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); IntentFilter intentFilter = new IntentFilter(S); Powiadomienia p = new Powiadomienia(); c.registerReceiver(p, intentFilter); am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60 * 10, pi); // Millisec * Sec * Min //am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), AlarmManager.INTERVAL_DAY, pi); // showToast("Powiadomienie wlaczone"); }
From source file:com.github.notizklotz.derbunddownloader.download.AutomaticIssueDownloadAlarmManager.java
public void updateAlarm() { //Update enforces reusing of an existing PendingIntent instance so AlarmManager.cancel(pi) //actually cancels the alarm. FLAG_CANCEL_CURRENT cancels the PendingIndent but then there's no //way to cancel the alarm programmatically. However, the Intent won't be executed anyway because //the fired alarm can't executed the cancelled PendingIntent. final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(context, AutomaticIssueDownloadAlarmReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); cancelAlarm(pendingIntent, sharedPreferences); if (Settings.isAutoDownloadEnabled(context)) { registerAlarm(pendingIntent);//ww w . ja v a2s. c om } }
From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java
@Override public void onDisabled(Context context) { super.onDisabled(context); // remove the update alarm if the last widget is gone Intent update = new Intent(UPDATE); PendingIntent pi = PendingIntent.getBroadcast(context, 195, update, 0); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.cancel(pi);/*w w w . ja v a 2s . com*/ }
From source file:com.google.android.apps.dashclock.PeriodicExtensionRefreshReceiver.java
/** * Sets the refresh schedule if one isn't set already. *///from w w w . j a va 2s.c o m public static void updateExtensionsAndEnsurePeriodicRefresh(final Context context) { LOGD(TAG, "updateExtensionsAndEnsurePeriodicRefresh"); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Update all extensions now. context.startService(getUpdateAllExtensionsIntent(context, DashClockExtension.UPDATE_REASON_MANUAL)); // Schedule an alarm for every 30 minutes; it will not wake up the device; // it will be handled only once the device is awake. The first time that this // alarm can go off is in 15 minutes, and the latest time it will go off is // 45 minutes from now. PendingIntent pi = PendingIntent.getBroadcast(context, 0, new Intent(context, PeriodicExtensionRefreshReceiver.class).setAction(ACTION_PERIODIC_ALARM), PendingIntent.FLAG_UPDATE_CURRENT); am.cancel(pi); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 15 * MINUTES_MILLIS, AlarmManager.INTERVAL_HALF_HOUR, pi); }
From source file:com.github.rutvijkumar.twittfuse.Util.java
public static final void scheduleAlarm(Activity activity) { // Construct an intent that will execute the AlarmReceiver Intent intent = new Intent(activity.getApplicationContext(), OfflineTweetAlarmReceiver.class); // Create a PendingIntent to be triggered when the alarm goes off final PendingIntent pIntent = PendingIntent.getBroadcast(activity, OfflineTweetAlarmReceiver.REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Setup periodic alarm every 10 seconds long firstMillis = System.currentTimeMillis(); // first run of alarm is // immediate//from w w w .j a va2s . c o m int intervalMillis = 10000; // 10 seconds AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE); alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstMillis, intervalMillis, pIntent); }
From source file:com.egoclean.arm.ui.ArmActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE); mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); registerReceiver(mUsbReceiver, filter); outputController = new OutputController(this); setContentView(R.layout.main);//from w w w. j a v a 2 s .c o m ArmView armView = (ArmView) findViewById(R.id.arm_view); armView.setAngleListener(outputController); mNotConnected = findViewById(R.id.lnl_not_connected); if (mAccessory != null) { showControls(); } else { hideControls(); } }
From source file:com.commonsware.android.deepbg.PollReceiver.java
static void cancelAlarm(Context ctxt, AlarmManager alarms) { Intent i = buildBaseIntent(ctxt); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); alarms.cancel(pi); }
From source file:com.bluros.updater.receiver.DownloadNotifier.java
private static PendingIntent createInstallPendingIntent(Context context, File updateFile) { Intent installIntent = new Intent(context, DownloadReceiver.class); installIntent.setAction(DownloadReceiver.ACTION_INSTALL_UPDATE); installIntent.putExtra(DownloadReceiver.EXTRA_FILENAME, updateFile.getName()); return PendingIntent.getBroadcast(context, 0, installIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.deepak.myclock.alarms.AlarmNotifications.java
public static void showLowPriorityNotification(Context context, AlarmInstance instance) { Log.v("Displaying low priority notification for alarm instance: " + instance.mId); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Resources resources = context.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(resources.getString(R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText(context, instance)) .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(false).setAutoCancel(false) .setPriority(NotificationCompat.PRIORITY_DEFAULT); // Setup up hide notification Intent hideIntent = AlarmStateManager.createStateChangeIntent(context, "DELETE_TAG", instance, AlarmInstance.HIDE_NOTIFICATION_STATE); notification.setDeleteIntent(PendingIntent.getBroadcast(context, instance.hashCode(), hideIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance, AlarmInstance.DISMISSED_STATE); notification.addAction(android.R.drawable.ic_menu_close_clear_cancel, resources.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getBroadcast(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId; Intent viewAlarmIntent = Alarm.createIntent(context, MainActivity.class, alarmId); //viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX); viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId); viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); nm.cancel(instance.hashCode());/* w w w .ja v a 2s . c om*/ nm.notify(instance.hashCode(), notification.build()); }