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.commonsware.android.messaging.RemoteInputReceiver.java
static NotificationCompat.Builder buildNotification(Context ctxt) { Intent i = new Intent(ctxt, RemoteInputReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInput = new RemoteInput.Builder(RemoteInputReceiver.EXTRA_INPUT) .setLabel(ctxt.getString(R.string.talk)).build(); NotificationCompat.Action remoteAction = new NotificationCompat.Action.Builder( android.R.drawable.ic_btn_speak_now, ctxt.getString(R.string.talk), pi).addRemoteInput(remoteInput) .build();/* ww w . ja va 2 s .c o m*/ NotificationCompat.MessagingStyle style = new NotificationCompat.MessagingStyle("Me") .setConversationTitle("A Fake Chat"); style.addMessage("Want to chat?", INITIAL_TIMESTAMP, "Somebody"); for (Message msg : MESSAGES) { style.addMessage(msg.text, msg.timestamp, style.getUserDisplayName()); } NotificationCompat.Builder builder = new NotificationCompat.Builder(ctxt) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setContentTitle(ctxt.getString(R.string.title)).setStyle(style).addAction(remoteAction); return (builder); }
From source file:com.tealeaf.PushBroadcastReceiver.java
public static void scheduleNext(Context context, int timeout) { TeaLeafOptions options = new TeaLeafOptions(context); String appID = options.getAppID(); logger.log("{push} Scheduling the next push for", timeout); Intent intent = new Intent("com.tealeaf.CHECK_PUSH_SERVER"); intent.putExtra("appID", appID); AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); scheduledIntent = PendingIntent.getBroadcast(context, 0, intent, 0); alarms.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (timeout * 1000), scheduledIntent); }
From source file:MainActivity.java
public void setAlarm(View view) { Intent intentToFire = new Intent(getApplicationContext(), AlarmBroadcastReceiver.class); intentToFire.setAction(AlarmBroadcastReceiver.ACTION_ALARM); PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intentToFire, 0); AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); long thirtyMinutes = SystemClock.elapsedRealtime() + 30 * 1000; alarmManager.set(AlarmManager.ELAPSED_REALTIME, thirtyMinutes, alarmIntent); //alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, thirtyMinutes, AlarmManager.INTERVAL_HALF_HOUR, alarmIntent); }
From source file:com.commonsware.android.job.PollReceiver.java
static void scheduleExactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) { Intent i = new Intent(ctxt, PollReceiver.class).putExtra(EXTRA_PERIOD, period).putExtra(EXTRA_IS_DOWNLOAD, isDownload);/*from w w w . ja v a 2 s.c o m*/ PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); alarms.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi); }
From source file:com.commonsware.android.deepbg.PollReceiver.java
static void scheduleExactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) { Intent i = buildBaseIntent(ctxt).putExtra(EXTRA_PERIOD, period).putExtra(EXTRA_IS_DOWNLOAD, isDownload); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { Log.e("PollReceiver", "allow while idle"); alarms.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { alarms.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi); } else {/* www .j ava2 s . c o m*/ alarms.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, pi); } }
From source file:com.commonsware.android.remoteinput.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent i = new Intent(this, RemoteInputReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInput = new RemoteInput.Builder(RemoteInputReceiver.EXTRA_INPUT) .setLabel(getString(R.string.talk)).build(); NotificationCompat.Action remoteAction = new NotificationCompat.Action.Builder( android.R.drawable.ic_btn_speak_now, getString(R.string.talk), pi).addRemoteInput(remoteInput) .build();//from ww w. j a v a 2 s . co m NotificationCompat.Builder builder = RemoteInputReceiver.buildNotificationBase(this) .addAction(remoteAction); NotificationManagerCompat.from(this).notify(RemoteInputReceiver.NOTIFY_ID, builder.build()); finish(); }
From source file:com.commonsware.android.job.PollReceiver.java
static void scheduleInexactAlarm(Context ctxt, AlarmManager alarms, long period, boolean isDownload) { Intent i = new Intent(ctxt, PollReceiver.class).putExtra(EXTRA_IS_DOWNLOAD, isDownload); PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0); alarms.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period, period, pi);/*from w w w . ja v a 2 s . c o m*/ }
From source file:com.commonsware.android.wearvoice.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent i = new Intent(this, VoiceReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInput = new RemoteInput.Builder(VoiceReceiver.EXTRA_SPEECH) .setLabel(getString(R.string.talk)).setChoices(getResources().getStringArray(R.array.replies)) .build();// w ww . j a va2 s .com NotificationCompat.Action wearAction = new NotificationCompat.Action.Builder( android.R.drawable.ic_btn_speak_now, getString(R.string.talk), pi).addRemoteInput(remoteInput) .build(); NotificationCompat.WearableExtender wearExtender = new NotificationCompat.WearableExtender() .addAction(wearAction); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(android.R.drawable.stat_sys_download_done).setContentTitle(getString(R.string.title)) .setContentText(getString(R.string.talk)).extend(wearExtender); NotificationManagerCompat.from(this).notify(NOTIFY_ID, builder.build()); finish(); }
From source file:com.cryart.sabbathschool.util.SSNotification.java
public static void setRepeatingNotification(Context context) { AlarmManager _SSAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent _SSNotificationIntent = new Intent(context, SSBroadcastReceiver.class); PendingIntent _SSAlarmIntent = PendingIntent.getBroadcast(context, 0, _SSNotificationIntent, 0); Calendar _SSNotificationTime = Calendar.getInstance(); SharedPreferences ssPreferences = PreferenceManager.getDefaultSharedPreferences(context); String ss_settings_notification_time = ssPreferences.getString( SSConstants.SS_SETTINGS_NOTIFICATION_TIME_KEY, SSConstants.SS_SETTINGS_NOTIFICATION_TIME_DEFAULT_VALUE); _SSNotificationTime.set(Calendar.HOUR_OF_DAY, SSHelper.parseHourFromString(ss_settings_notification_time, SSConstants.SS_NOTIFICATION_TIME_SETTINGS_FORMAT)); _SSNotificationTime.set(Calendar.MINUTE, SSHelper.parseMinuteFromString(ss_settings_notification_time, SSConstants.SS_NOTIFICATION_TIME_SETTINGS_FORMAT)); _SSNotificationTime.set(Calendar.SECOND, 0); _SSAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, _SSNotificationTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, _SSAlarmIntent); }
From source file:cat.wuyingren.whatsannoy.utils.SystemUtils.java
public static void createAlarm(Context context, Schedule schedule) { Log.w("UTILS", "createAlarm() / Scheduled: " + schedule.getId()); Intent alarmIntent = new Intent(context, Alarm.class); alarmIntent.putExtra(Alarm.PREF_ALARM_ID, schedule.getId()); PendingIntent pi = PendingIntent.getBroadcast(context, SystemUtils.safeLongToInt(schedule.getId()), alarmIntent, 0);//from www .j av a2 s .com AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmMgr.set(AlarmManager.RTC_WAKEUP, schedule.getDate(), pi); }