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:be.ppareit.swiftp.gui.FsNotification.java
private void setupNotification(Context context) { Cat.d("Setting up the notification"); // Get NotificationManager reference String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) context.getSystemService(ns); // get ip address InetAddress address = FsService.getLocalInetAddress(); if (address == null) { Cat.w("Unable to retrieve the local ip address"); return;/*from www . j av a 2 s .c o m*/ } String iptext = "ftp://" + address.getHostAddress() + ":" + FsSettings.getPortNumber() + "/"; // Instantiate a Notification int icon = R.mipmap.notification; CharSequence tickerText = String.format(context.getString(R.string.notification_server_starting), iptext); long when = System.currentTimeMillis(); // Define Notification's message and Intent CharSequence contentTitle = context.getString(R.string.notification_title); CharSequence contentText = String.format(context.getString(R.string.notification_text), iptext); Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); int stopIcon = android.R.drawable.ic_menu_close_clear_cancel; CharSequence stopText = context.getString(R.string.notification_stop_text); Intent stopIntent = new Intent(FsService.ACTION_STOP_FTPSERVER); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context, 0, stopIntent, PendingIntent.FLAG_ONE_SHOT); int preferenceIcon = android.R.drawable.ic_menu_preferences; CharSequence preferenceText = context.getString(R.string.notif_settings_text); Intent preferenceIntent = new Intent(context, MainActivity.class); preferenceIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent preferencePendingIntent = PendingIntent.getActivity(context, 0, preferenceIntent, 0); Notification notification = new NotificationCompat.Builder(context).setContentTitle(contentTitle) .setContentText(contentText).setContentIntent(contentIntent).setSmallIcon(icon) .setTicker(tickerText).setWhen(when).setOngoing(true) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_SERVICE).setPriority(NotificationCompat.PRIORITY_MAX) .addAction(stopIcon, stopText, stopPendingIntent) .addAction(preferenceIcon, preferenceText, preferencePendingIntent).setShowWhen(false).build(); // Pass Notification to NotificationManager nm.notify(NOTIFICATION_ID, notification); Cat.d("Notification setup done"); }
From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java
public void setAlarm(Context context, Calendar calendar, int ID) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AutomuteAlarmReceiver.class); intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification time Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using notification time mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); // update all added list widgets for (int appWidgetId : appWidgetIds) { onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, null); }/* ww w . j ava2 s . c om*/ // set an alarm to update widgets every x mins if the device is awake Intent update = new Intent(UPDATE); PendingIntent pi = PendingIntent.getBroadcast(context, 195, update, 0); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + REPETITION_INTERVAL, REPETITION_INTERVAL, pi); }
From source file:com.cpd.receivers.LibraryRenewAlarmBroadcastReceiver.java
public void setAlarm(Context context) { Log.d(TAG, "setAlarm() called with: " + "context = [" + context + "]"); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 12); calendar.set(Calendar.MINUTE, 1); calendar.set(Calendar.SECOND, 0); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, LibraryRenewAlarmBroadcastReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, 1, intent, 0); am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY / DAILY_RETRIES, pi); }
From source file:com.android.transmart.services.PlaceCheckinService.java
@Override public void onCreate() { super.onCreate(); contentResolver = getContentResolver(); cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); sharedPreferences = getSharedPreferences(LocationConstants.SHARED_PREFERENCE_FILE, Context.MODE_PRIVATE); sharedPreferencesEditor = sharedPreferences.edit(); sharedPref = PlatformSpecific.getSharedPreferenceSaver(this); Intent retryIntent = new Intent(LocationConstants.RETRY_QUEUED_CHECKINS_ACTION); retryQueuedCheckinsPendingIntent = PendingIntent.getBroadcast(this, 0, retryIntent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.android.tripgenie.auto.MessagingService.java
private void sendNotificationForConversation(int conversationId, String sender, String message, long timestamp) { String contentTitle;// w w w . j av a2 s . c om if (message.indexOf(" is ") > 0) { contentTitle = message.substring(0, message.indexOf(" is ")); } else { contentTitle = message; } // A pending Intent for reads PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId, getMessageReadIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT); /// Add the code to create the UnreadConversation // Build a RemoteInput for receiving voice input in a Car Notification RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build(); // Building a Pending Intent for the reply action to trigger PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId, getMessageReplyIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT); // Create the UnreadConversation and populate it with the participant name, // read and reply intents. UnreadConversation.Builder unreadConversationBuilder = new UnreadConversation.Builder(contentTitle) .setLatestTimestamp(timestamp).setReadPendingIntent(readPendingIntent) .setReplyAction(replyIntent, remoteInput); // Note: Add messages from oldest to newest to the UnreadConversation.Builder // Since we are sending a single message here we simply add the message. // In a real world application there could be multiple messages which should be ordered // and added from oldest to newest. unreadConversationBuilder.addMessage(message); /// End create UnreadConversation NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.notification_icon) .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.android_contact)) .setContentText(message) //.setWhen(timestamp) .setOngoing(true).setContentTitle(contentTitle).setContentIntent(readPendingIntent) /// Extend the notification with CarExtender. .extend(new CarExtender().setUnreadConversation(unreadConversationBuilder.build())) /// End ; Log.d(TAG, "Sending notification " + conversationId + " conversation: " + message); NotificationManagerCompat.from(this).notify(conversationId, builder.build()); }
From source file:be.ac.ucl.lfsab1509.llncampus.services.AlarmService.java
@Override public void onCreate() { super.onCreate(); // Define the Context here, otherwise no Context before launching the application. LLNCampus.setContext(getApplicationContext()); am = (AlarmManager) LLNCampus.getContext().getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(LLNCampus.getContext(), AlarmService.class); PendingIntent pi = PendingIntent.getBroadcast(LLNCampus.getContext(), 0, i, 0); am.set(AlarmManager.ELAPSED_REALTIME, TIME_TO_REPEAT, pi); }
From source file:com.allthatseries.RNAudioPlayer.MediaNotificationManager.java
public MediaNotificationManager(AudioPlayerService service) throws RemoteException { mService = service;/*from w w w . j av a 2 s .c o m*/ updateSessionToken(); mNotificationManager = NotificationManagerCompat.from(service); String pkg = mService.getPackageName(); mPauseIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PAUSE).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mPlayIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PLAY).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mPreviousIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PREV).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); mNextIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_NEXT).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT); // Cancel all notifications to handle the case where the Service was killed and // restarted by the system. mNotificationManager.cancelAll(); }
From source file:com.ferdi2005.secondgram.MusicPlayerService.java
@SuppressLint("NewApi") @Override// w w w . j av a 2s. c o m public int onStartCommand(Intent intent, int flags, int startId) { try { MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject(); if (messageObject == null) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { stopSelf(); } }); return START_STICKY; } if (supportLockScreenControls) { ComponentName remoteComponentName = new ComponentName(getApplicationContext(), MusicPlayerReceiver.class.getName()); try { if (remoteControlClient == null) { audioManager.registerMediaButtonEventReceiver(remoteComponentName); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(remoteComponentName); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0); remoteControlClient = new RemoteControlClient(mediaPendingIntent); audioManager.registerRemoteControlClient(remoteControlClient); } remoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT); } catch (Exception e) { FileLog.e(e); } } createNotification(messageObject); } catch (Exception e) { e.printStackTrace(); } return START_STICKY; }
From source file:com.cssweb.android.base.BaseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); toolbarClick = new ToolbarClick(); alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, AutoReceiver.class); pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); // ParamSetting.getInstance().setIsEnternal(false); // ParamSetting.getInstance().setInterval(20000); ServiceControl sControl = new ServiceControl(this); ServiceControl.startScreenReceiver(); ServiceControl.startHomeReceiver();/*from w w w.j a v a 2s. co m*/ listenScreen(); sControl.startTrackService(); }