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.adityarathi.muo.services.AudioPlaybackService.java
/** * Builds and returns a fully constructed Notification for devices * on Jelly Bean and above (API 16+).//from w w w .ja v a 2 s .c o m */ @SuppressLint("NewApi") private Notification buildJBNotification(SongHelper songHelper) { mNotificationBuilder = new NotificationCompat.Builder(mContext); mNotificationBuilder.setOngoing(true); mNotificationBuilder.setAutoCancel(false); mNotificationBuilder.setSmallIcon(R.mipmap.ic_launcher); //Open up the player screen when the user taps on the notification. Intent launchNowPlayingIntent = new Intent(); launchNowPlayingIntent.setAction(AudioPlaybackService.LAUNCH_NOW_PLAYING_ACTION); PendingIntent launchNowPlayingPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, launchNowPlayingIntent, 0); mNotificationBuilder.setContentIntent(launchNowPlayingPendingIntent); //Grab the notification layouts. RemoteViews notificationView = new RemoteViews(mContext.getPackageName(), R.layout.notification_custom_layout); RemoteViews expNotificationView = new RemoteViews(mContext.getPackageName(), R.layout.notification_custom_expanded_layout); //Initialize the notification layout buttons. Intent previousTrackIntent = new Intent(); previousTrackIntent.setAction(AudioPlaybackService.PREVIOUS_ACTION); PendingIntent previousTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, previousTrackIntent, 0); Intent playPauseTrackIntent = new Intent(); playPauseTrackIntent.setAction(AudioPlaybackService.PLAY_PAUSE_ACTION); PendingIntent playPauseTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, playPauseTrackIntent, 0); Intent nextTrackIntent = new Intent(); nextTrackIntent.setAction(AudioPlaybackService.NEXT_ACTION); PendingIntent nextTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, nextTrackIntent, 0); Intent stopServiceIntent = new Intent(); stopServiceIntent.setAction(AudioPlaybackService.STOP_SERVICE); PendingIntent stopServicePendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, stopServiceIntent, 0); //Check if audio is playing and set the appropriate play/pause button. if (mApp.getService().isPlayingMusic()) { notificationView.setImageViewResource(R.id.notification_base_play, R.drawable.ic_play); expNotificationView.setImageViewResource(R.id.notification_expanded_base_play, R.drawable.ic_play); } else { notificationView.setImageViewResource(R.id.notification_base_play, R.drawable.ic_play); expNotificationView.setImageViewResource(R.id.notification_expanded_base_play, R.drawable.ic_play); } //Set the notification content. expNotificationView.setTextViewText(R.id.notification_expanded_base_line_one, songHelper.getTitle()); expNotificationView.setTextViewText(R.id.notification_expanded_base_line_two, songHelper.getArtist()); expNotificationView.setTextViewText(R.id.notification_expanded_base_line_three, songHelper.getAlbum()); notificationView.setTextViewText(R.id.notification_base_line_one, songHelper.getTitle()); notificationView.setTextViewText(R.id.notification_base_line_two, songHelper.getArtist()); //Set the states of the next/previous buttons and their pending intents. if (mApp.getService().isOnlySongInQueue()) { //This is the only song in the queue, so disable the previous/next buttons. expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.INVISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.INVISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE); notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); } else if (mApp.getService().isFirstSongInQueue()) { //This is the the first song in the queue, so disable the previous button. expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.INVISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.VISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next, nextTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE); notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent); } else if (mApp.getService().isLastSongInQueue()) { //This is the last song in the cursor, so disable the next button. expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.VISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.INVISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next, nextTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE); notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent); } else { //We're smack dab in the middle of the queue, so keep the previous and next buttons enabled. expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.VISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.VISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next, nextTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_previous, previousTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE); notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_previous, previousTrackPendingIntent); } //Set the "Stop Service" pending intents. expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_collapse, stopServicePendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_collapse, stopServicePendingIntent); //Set the album art. expNotificationView.setImageViewBitmap(R.id.notification_expanded_base_image, songHelper.getAlbumArt()); notificationView.setImageViewBitmap(R.id.notification_base_image, songHelper.getAlbumArt()); //Attach the shrunken layout to the notification. mNotificationBuilder.setContent(notificationView); //Build the notification object. Notification notification = mNotificationBuilder.build(); //Attach the expanded layout to the notification and set its flags. notification.bigContentView = expNotificationView; notification.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; return notification; }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** * Called when download has been completed. * @param content content./*from w w w .java2 s. c o m*/ */ void onDownloadComplete(EngagementReachInteractiveContent content) { /* Cancel alarm */ Intent intent = new Intent(INTENT_ACTION_DOWNLOAD_TIMEOUT); intent.setPackage(mContext.getPackageName()); int requestCode = (int) content.getLocalId(); PendingIntent operation = PendingIntent.getBroadcast(mContext, requestCode, intent, 0); AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(operation); /* Update notification if not too late e.g. notification not yet dismissed */ notifyPendingContent(content); }
From source file:com.aniruddhc.acemusic.player.Services.AudioPlaybackService.java
/** * Builds and returns a fully constructed Notification for devices * on Jelly Bean and above (API 16+)./*from w w w . j a va2 s. co m*/ */ @SuppressLint("NewApi") private Notification buildJBNotification(SongHelper songHelper) { mNotificationBuilder = new NotificationCompat.Builder(mContext); mNotificationBuilder.setOngoing(true); mNotificationBuilder.setAutoCancel(false); mNotificationBuilder.setSmallIcon(R.drawable.notif_icon); //Open up the player screen when the user taps on the notification. Intent launchNowPlayingIntent = new Intent(); launchNowPlayingIntent.setAction(AudioPlaybackService.LAUNCH_NOW_PLAYING_ACTION); PendingIntent launchNowPlayingPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, launchNowPlayingIntent, 0); mNotificationBuilder.setContentIntent(launchNowPlayingPendingIntent); //Grab the notification layouts. RemoteViews notificationView = new RemoteViews(mContext.getPackageName(), R.layout.notification_custom_layout); RemoteViews expNotificationView = new RemoteViews(mContext.getPackageName(), R.layout.notification_custom_expanded_layout); //Initialize the notification layout buttons. Intent previousTrackIntent = new Intent(); previousTrackIntent.setAction(AudioPlaybackService.PREVIOUS_ACTION); PendingIntent previousTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, previousTrackIntent, 0); Intent playPauseTrackIntent = new Intent(); playPauseTrackIntent.setAction(AudioPlaybackService.PLAY_PAUSE_ACTION); PendingIntent playPauseTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, playPauseTrackIntent, 0); Intent nextTrackIntent = new Intent(); nextTrackIntent.setAction(AudioPlaybackService.NEXT_ACTION); PendingIntent nextTrackPendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, nextTrackIntent, 0); Intent stopServiceIntent = new Intent(); stopServiceIntent.setAction(AudioPlaybackService.STOP_SERVICE); PendingIntent stopServicePendingIntent = PendingIntent.getBroadcast(mContext.getApplicationContext(), 0, stopServiceIntent, 0); //Check if audio is playing and set the appropriate play/pause button. if (mApp.getService().isPlayingMusic()) { notificationView.setImageViewResource(R.id.notification_base_play, R.drawable.btn_playback_pause_light); expNotificationView.setImageViewResource(R.id.notification_expanded_base_play, R.drawable.btn_playback_pause_light); } else { notificationView.setImageViewResource(R.id.notification_base_play, R.drawable.btn_playback_play_light); expNotificationView.setImageViewResource(R.id.notification_expanded_base_play, R.drawable.btn_playback_play_light); } //Set the notification content. expNotificationView.setTextViewText(R.id.notification_expanded_base_line_one, songHelper.getTitle()); expNotificationView.setTextViewText(R.id.notification_expanded_base_line_two, songHelper.getArtist()); expNotificationView.setTextViewText(R.id.notification_expanded_base_line_three, songHelper.getAlbum()); notificationView.setTextViewText(R.id.notification_base_line_one, songHelper.getTitle()); notificationView.setTextViewText(R.id.notification_base_line_two, songHelper.getArtist()); //Set the states of the next/previous buttons and their pending intents. if (mApp.getService().isOnlySongInQueue()) { //This is the only song in the queue, so disable the previous/next buttons. expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.INVISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.INVISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE); notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); } else if (mApp.getService().isFirstSongInQueue()) { //This is the the first song in the queue, so disable the previous button. expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.INVISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.VISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next, nextTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_previous, View.INVISIBLE); notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent); } else if (mApp.getService().isLastSongInQueue()) { //This is the last song in the cursor, so disable the next button. expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.VISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.INVISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next, nextTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE); notificationView.setViewVisibility(R.id.notification_base_next, View.INVISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent); } else { //We're smack dab in the middle of the queue, so keep the previous and next buttons enabled. expNotificationView.setViewVisibility(R.id.notification_expanded_base_previous, View.VISIBLE); expNotificationView.setViewVisibility(R.id.notification_expanded_base_next, View.VISIBLE); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_play, playPauseTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_next, nextTrackPendingIntent); expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_previous, previousTrackPendingIntent); notificationView.setViewVisibility(R.id.notification_base_previous, View.VISIBLE); notificationView.setViewVisibility(R.id.notification_base_next, View.VISIBLE); notificationView.setOnClickPendingIntent(R.id.notification_base_play, playPauseTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_next, nextTrackPendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_previous, previousTrackPendingIntent); } //Set the "Stop Service" pending intents. expNotificationView.setOnClickPendingIntent(R.id.notification_expanded_base_collapse, stopServicePendingIntent); notificationView.setOnClickPendingIntent(R.id.notification_base_collapse, stopServicePendingIntent); //Set the album art. expNotificationView.setImageViewBitmap(R.id.notification_expanded_base_image, songHelper.getAlbumArt()); notificationView.setImageViewBitmap(R.id.notification_base_image, songHelper.getAlbumArt()); //Attach the shrunken layout to the notification. mNotificationBuilder.setContent(notificationView); //Build the notification object. Notification notification = mNotificationBuilder.build(); //Attach the expanded layout to the notification and set its flags. notification.bigContentView = expNotificationView; notification.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; return notification; }
From source file:com.mobicage.rpc.http.HttpCommunicator.java
private void scheduleRetryCommunication() { final Intent intent = new Intent(INTENT_SHOULD_RETRY_COMMUNICATION); long triggerAtMillis = System.currentTimeMillis() + COMMUNICATION_RETRY_INTERVAL; mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, PendingIntent.getBroadcast(mMainService, 0, intent, 0)); }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void notifySecondDMs(Context context, int secondAccount) { DMDataSource data = DMDataSource.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int numberNew = sharedPrefs.getInt("dm_unread_" + secondAccount, 0); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;/* w w w . j a v a 2s . c o m*/ NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); String name; String message; String messageLong; NotificationCompat.InboxStyle inbox = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; messageLong = "<b>@" + name + "</b>: " + data.getNewestMessage(secondAccount); largeIcon = getImage(context, name); } else { // more than one dm message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); inbox = getDMInboxStyle(numberNew, secondAccount, context, message); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setAutoCancel(true).setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:com.dwdesign.tweetings.service.TweetingsService.java
private Notification buildNotification(final String title, final String message, final int icon, final Intent content_intent, final Intent delete_intent) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setTicker(message);//from w w w . j a v a 2s.c o m builder.setContentTitle(title); builder.setContentText(message); builder.setAutoCancel(true); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(icon); if (delete_intent != null) { builder.setDeleteIntent( PendingIntent.getBroadcast(this, 0, delete_intent, PendingIntent.FLAG_UPDATE_CURRENT)); } if (content_intent != null) { builder.setContentIntent( PendingIntent.getActivity(this, 0, content_intent, PendingIntent.FLAG_UPDATE_CURRENT)); } int defaults = 0; final Calendar now = Calendar.getInstance(); if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_SOUND, true) && !mPreferences.getBoolean("silent_notifications_at_" + now.get(Calendar.HOUR_OF_DAY), false)) { Uri soundUri = Uri.parse(mPreferences.getString(PREFERENCE_KEY_NOTIFICATION_RINGTONE, "android.resource://" + getPackageName() + "/" + R.raw.notify)); builder.setSound(soundUri, Notification.STREAM_DEFAULT); } if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_VIBRATION, true) && !mPreferences.getBoolean("silent_notifications_at_" + now.get(Calendar.HOUR_OF_DAY), false)) { defaults |= Notification.DEFAULT_VIBRATE; } if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_LIGHTS, true) && !mPreferences.getBoolean("silent_notifications_at_" + now.get(Calendar.HOUR_OF_DAY), false)) { final int color_def = getResources().getColor(R.color.holo_blue_dark); final int color = mPreferences.getInt(PREFERENCE_KEY_NOTIFICATION_LIGHT_COLOR, color_def); builder.setLights(color, 1000, 2000); } builder.setDefaults(defaults); return builder.getNotification(); }
From source file:RhodesService.java
private void updateDownloadNotification(String url, int totalBytes, int currentBytes) { Context context = RhodesActivity.getContext(); Notification n = new Notification(); n.icon = android.R.drawable.stat_sys_download; n.flags |= Notification.FLAG_ONGOING_EVENT; RemoteViews expandedView = new RemoteViews(context.getPackageName(), R.layout.status_bar_ongoing_event_progress_bar); StringBuilder newUrl = new StringBuilder(); if (url.length() < 17) newUrl.append(url);//from w ww.j av a 2 s . co m else { newUrl.append(url.substring(0, 7)); newUrl.append("..."); newUrl.append(url.substring(url.length() - 7, url.length())); } expandedView.setTextViewText(R.id.title, newUrl.toString()); StringBuffer downloadingText = new StringBuffer(); if (totalBytes > 0) { long progress = currentBytes * 100 / totalBytes; downloadingText.append(progress); downloadingText.append('%'); } expandedView.setTextViewText(R.id.progress_text, downloadingText.toString()); expandedView.setProgressBar(R.id.progress_bar, totalBytes < 0 ? 100 : totalBytes, currentBytes, totalBytes < 0); n.contentView = expandedView; Intent intent = new Intent(ACTION_ASK_CANCEL_DOWNLOAD); n.contentIntent = PendingIntent.getBroadcast(context, 0, intent, 0); intent = new Intent(ACTION_CANCEL_DOWNLOAD); n.deleteIntent = PendingIntent.getBroadcast(context, 0, intent, 0); mNM.notify(DOWNLOAD_PACKAGE_ID, n); }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void notifySecondDMs(Context context, int secondAccount) { DMDataSource data = DMDataSource.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int numberNew = sharedPrefs.getInt("dm_unread_" + secondAccount, 0); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;// w ww . j ava 2 s. c o m Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); String name; String message; String messageLong; NotificationCompat.InboxStyle inbox = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; messageLong = "<b>@" + name + "</b>: " + data.getNewestMessage(secondAccount); largeIcon = getImage(context, name); } else { // more than one dm message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); inbox = getDMInboxStyle(numberNew, secondAccount, context, message); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setAutoCancel(true) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:com.mobilyzer.MeasurementScheduler.java
/** Set the interval for checkin in seconds */ public synchronized long setCheckinInterval(boolean isForced, long interval) { Logger.d("Scheduler->setCheckinInterval called " + interval); long min = Config.MIN_CHECKIN_INTERVAL_SEC; long max = Config.MAX_CHECKIN_INTERVAL_SEC; if (!isForced && this.checkinIntervalSec != -1) { min = this.batteryThreshold; }//from w ww. ja v a 2 s. c om // Check whether out of boundary and same with old value if (interval >= min && interval <= max && interval != this.checkinIntervalSec) { this.checkinIntervalSec = interval; Logger.i("Setting checkin interval to " + this.checkinIntervalSec + " seconds"); persistParams(Config.PREF_KEY_CHECKIN_INTERVAL, String.valueOf(this.checkinIntervalSec)); // 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); } return this.checkinIntervalSec; }
From source file:com.xorcode.andtweet.AndTweetService.java
/** * Notify user of the commands Queue size * /*from w w w .j ava2 s . c om*/ * @return total size of Queues */ private int notifyOfQueue(boolean clearNotification) { int count = mRetryQueue.size() + mCommands.size(); NotificationManager nM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if (count == 0 || clearNotification) { // Clear notification nM.cancel(CommandEnum.NOTIFY_QUEUE.ordinal()); } else if (mNotificationsEnabled) { if (mRetryQueue.size() > 0) { MyLog.d(TAG, mRetryQueue.size() + " commands in Retry Queue."); } if (mCommands.size() > 0) { MyLog.d(TAG, mCommands.size() + " commands in Main Queue."); } // Set up the notification to display to the user Notification notification = new Notification(R.drawable.notification_icon, (String) getText(R.string.notification_title), System.currentTimeMillis()); int messageTitle; String aMessage = ""; aMessage = I18n.formatQuantityMessage(getApplicationContext(), R.string.notification_queue_format, count, R.array.notification_queue_patterns, R.array.notification_queue_formats); messageTitle = R.string.notification_title_queue; // Set up the scrolling message of the notification notification.tickerText = aMessage; /** * Set the latest event information and send the notification * Actually don't start any intent * * @see http * ://stackoverflow.com/questions/4232006/android-notification * -pendingintent-problem */ // PendingIntent pi = PendingIntent.getActivity(this, 0, null, 0); /** * Kick the commands queue by sending empty command */ PendingIntent pi = PendingIntent.getBroadcast(this, 0, new CommandData(CommandEnum.EMPTY).toIntent(), 0); notification.setLatestEventInfo(this, getText(messageTitle), aMessage, pi); nM.notify(CommandEnum.NOTIFY_QUEUE.ordinal(), notification); } return count; }