List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:com.otaupdater.utils.RomInfo.java
public void showUpdateNotif(Context ctx) { Intent mainInent = new Intent(ctx, TabDisplay.class); mainInent.setAction(TabDisplay.ROM_NOTIF_ACTION); this.addToIntent(mainInent); PendingIntent mainPIntent = PendingIntent.getActivity(ctx, 0, mainInent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlInent = new Intent(ctx, DownloadReceiver.class); dlInent.setAction(DownloadReceiver.DL_ROM_ACTION); this.addToIntent(dlInent); PendingIntent dlPIntent = PendingIntent.getBroadcast(ctx, 0, dlInent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx); builder.setContentIntent(mainPIntent); builder.setContentTitle(ctx.getString(R.string.notif_source)); builder.setContentText(ctx.getString(R.string.notif_text_rom)); builder.setTicker(ctx.getString(R.string.notif_text_rom)); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(R.drawable.updates); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(changelog)); builder.setPriority(NotificationCompat.PRIORITY_LOW); builder.addAction(R.drawable.ic_download_default, ctx.getString(R.string.notif_download), dlPIntent); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(Config.ROM_NOTIF_ID, builder.build()); }
From source file:com.brightsilence.dev.androidphotobackup.PhotoBackupService.java
private void doNotification(String notificationText) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Android Photo Backup Complete") .setContentText(notificationText); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, PhotoBackupSettingsActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(PhotoBackupSettingsActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(m_notificationId, mBuilder.build()); }
From source file:com.alivenet.dmvtaxi.FcmUtil.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./* ww w .j a va 2s . c o m*/ */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void sendNotification(String message) { SharedPreference sharedPreference = new SharedPreference(); if (splitnotifiaction_flag) { intent = new Intent(this, AcceptNotificationUIwork.class); if (flag == true) { intent.putExtra("ridedriverInfo", MyApplication.rideDriverComplete); intent.putExtra("flag", flag); } } else { intent = new Intent(this, DeashboardActivity.class); if (flag == true) { intent.putExtra("ridedriverInfo", MyApplication.rideDriverComplete); intent.putExtra("flag", flag); } intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Notification").setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); } }
From source file:com.easibeacon.examples.shop.MainActivity.java
public void createNotification(String title, String content, String monumentId) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.notification).setContentTitle(title).setContentText(content); Intent resultIntent = new Intent(getApplicationContext(), MonumentActivity.class); Log.i("Monument", monumentId); resultIntent.putExtra("id", monumentId); PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotifyMgr.notify(Integer.parseInt(monumentId), mBuilder.build()); //arrayAdapter.notifyDataSetChanged(); }
From source file:com.conferenceengineer.android.iosched.service.SessionAlarmService.java
private void notifySession(final long sessionStart, final long sessionEnd, final long alarmOffset) { long currentTime; if (sessionStart < (currentTime = UIUtils.getCurrentTime(this))) return;//from w w w.j a va 2 s.co m // Avoid repeated notifications. if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this, ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd))) { return; } final ContentResolver cr = getContentResolver(); final Uri starredBlockUri = ScheduleContract.Blocks .buildStarredSessionsUri(ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd)); Cursor c = cr.query(starredBlockUri, SessionDetailQuery.PROJECTION, null, null, null); int starredCount = 0; ArrayList<String> starredSessionTitles = new ArrayList<String>(); ArrayList<String> starredSessionRoomIds = new ArrayList<String>(); String sessionId = null; // needed to get session track icon while (c.moveToNext()) { sessionId = c.getString(SessionDetailQuery.SESSION_ID); starredCount = c.getInt(SessionDetailQuery.NUM_STARRED_SESSIONS); starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE)); starredSessionRoomIds.add(c.getString(SessionDetailQuery.ROOM_ID)); } if (starredCount < 1) { return; } // Generates the pending intent which gets fired when the user taps on the notification. // NOTE: Use TaskStackBuilder to comply with Android's design guidelines // related to navigation from notifications. PendingIntent pi = TaskStackBuilder.create(this).addNextIntent(new Intent(this, HomeActivity.class)) .addNextIntent(new Intent(Intent.ACTION_VIEW, starredBlockUri)) .getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); final Resources res = getResources(); String contentText; int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000; if (minutesLeft < 1) { minutesLeft = 1; } if (starredCount == 1) { contentText = res.getString(R.string.session_notification_text_1, minutesLeft); } else { contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft, starredCount - 1); } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText) .setTicker(res.getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount)) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.conference_ic_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true); if (starredCount == 1) { // get the track icon to show as the notification big picture Uri tracksUri = ScheduleContract.Sessions.buildTracksDirUri(sessionId); Cursor tracksCursor = cr.query(tracksUri, SessionTrackQuery.PROJECTION, null, null, null); if (tracksCursor.moveToFirst()) { String trackName = tracksCursor.getString(SessionTrackQuery.TRACK_NAME); int trackColour = tracksCursor.getInt(SessionTrackQuery.TRACK_COLOR); Bitmap trackIcon = UIUtils.getTrackIconSync(getApplicationContext(), trackName, trackColour); if (trackIcon != null) { notifBuilder.setLargeIcon(trackIcon); } } } if (minutesLeft > 5) { notifBuilder.addAction(R.drawable.ic_alarm_holo_dark, String.format(res.getString(R.string.snooze_x_min), 5), createSnoozeIntent(sessionStart, sessionEnd, 5)); } NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder) .setBigContentTitle(res.getQuantityString(R.plurals.session_notification_title, starredCount, minutesLeft, starredCount)); // Adds starred sessions starting at this time block to the notification. for (int i = 0; i < starredCount; i++) { richNotification.addLine(starredSessionTitles.get(i)); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, richNotification.build()); }
From source file:at.bitfire.davdroid.syncadapter.DavSyncAdapter.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override// w w w. j a v a 2s.c o m public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Log.i(TAG, "Performing sync for authority " + authority); /* Set class loader for iCal4j ResourceLoader this is required because the various * sync adapters (contacts, events, tasks) share the same :sync process (see AndroidManifest */ Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); // create httpClient, if necessary httpClientLock.writeLock().lock(); if (httpClient == null) { Log.d(TAG, "Creating new DavHttpClient"); httpClient = DavHttpClient.create(); } // prevent httpClient shutdown until we're ready by holding a read lock // acquiring read lock before releasing write lock will downgrade the write lock to a read lock httpClientLock.readLock().lock(); httpClientLock.writeLock().unlock(); Exception exceptionToShow = null; // exception to show notification for Intent exceptionIntent = null; // what shall happen when clicking on the exception notification try { // get local <-> remote collection pairs Map<LocalCollection<?>, WebDavCollection<?>> syncCollections = getSyncPairs(account, provider); if (syncCollections == null) Log.i(TAG, "Nothing to synchronize"); else try { for (Map.Entry<LocalCollection<?>, WebDavCollection<?>> entry : syncCollections.entrySet()) new SyncManager(entry.getKey(), entry.getValue()) .synchronize(extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult); } catch (DavException ex) { syncResult.stats.numParseExceptions++; Log.e(TAG, "Invalid DAV response", ex); exceptionToShow = ex; } catch (HttpException ex) { if (ex.getCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "HTTP Unauthorized " + ex.getCode(), ex); syncResult.stats.numAuthExceptions++; // hard error exceptionToShow = ex; exceptionIntent = new Intent(context, AccountActivity.class); exceptionIntent.putExtra(AccountActivity.EXTRA_ACCOUNT, account); } else if (ex.isClientError()) { Log.e(TAG, "Hard HTTP error " + ex.getCode(), ex); syncResult.stats.numParseExceptions++; // hard error exceptionToShow = ex; } else { Log.w(TAG, "Soft HTTP error " + ex.getCode() + " (Android will try again later)", ex); syncResult.stats.numIoExceptions++; // soft error } } catch (LocalStorageException ex) { syncResult.databaseError = true; // hard error Log.e(TAG, "Local storage (content provider) exception", ex); exceptionToShow = ex; } catch (IOException ex) { syncResult.stats.numIoExceptions++; // soft error Log.e(TAG, "I/O error (Android will try again later)", ex); if (ex instanceof SSLException) // always notify on SSL/TLS errors exceptionToShow = ex; } catch (URISyntaxException ex) { syncResult.stats.numParseExceptions++; // hard error Log.e(TAG, "Invalid URI (file name) syntax", ex); exceptionToShow = ex; } } finally { // allow httpClient shutdown httpClientLock.readLock().unlock(); } // show sync errors as notification if (exceptionToShow != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (exceptionIntent == null) exceptionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.WEB_URL_VIEW_LOGS)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, exceptionIntent, 0); Notification.Builder builder = new Notification.Builder(context).setSmallIcon(R.drawable.ic_launcher) .setPriority(Notification.PRIORITY_LOW).setOnlyAlertOnce(true) .setWhen(System.currentTimeMillis()) .setContentTitle(context.getString(R.string.sync_error_title)) .setContentText(exceptionToShow.getLocalizedMessage()).setContentInfo(account.name) .setStyle(new Notification.BigTextStyle() .bigText(account.name + ":\n" + ExceptionUtils.getStackTrace(exceptionToShow))) .setContentIntent(contentIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(account.name.hashCode(), builder.build()); } Log.i(TAG, "Sync complete for " + authority); }
From source file:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java
private void notifyMatch(long matchId) { if (!PrefUtils.shouldShowMatchReminders(this)) { return;/* www . ja v a2 s . c om*/ } final ContentResolver cr = getContentResolver(); Cursor c = cr.query(MatchContract.SeriesEntry.CONTENT_URI, MatchDetailQuery.PROJECTION, SESSION_ID_WHERE_CLAUSE, new String[] { String.valueOf(matchId) }, null); if (!c.moveToNext()) { return; } Intent baseIntent = new Intent(this, MatchActivity.class); baseIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent); Intent matchIntent = new Intent(this, MatchDetailActivity.class); matchIntent.putExtra(MatchDetailActivity.ARGS_GG_MATCH_ID, matchId); taskBuilder.addNextIntent(matchIntent); PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); final Resources res = getResources(); String contentTitle = c.getString(MatchDetailQuery.TEAM_ONE_NAME) + " vs " + c.getString(MatchDetailQuery.TEAM_TWO_NAME); String contentText; long currentTime = TimeUtils.getUTCTime(); long matchStart = c.getLong(MatchDetailQuery.DATE_TIME); int minutesLeft = (int) (matchStart - currentTime + 59000) / 60000; if (minutesLeft < 2 && minutesLeft >= 0) { minutesLeft = 1; } if (minutesLeft < 0) { contentText = "is scheduled to start now. (" + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")"; } else { contentText = "is scheduled to start in " + minutesLeft + " min. (" + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")"; } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this).setContentTitle(contentTitle) .setContentText(contentText).setColor(res.getColor(R.color.theme_primary)) .setTicker(contentTitle + " is about to start.") .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(NOTIFICATION_ARGB_COLOR, NOTIFICATION_LED_ON_MS, NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_DEFAULT).setAutoCancel(true); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notifBuilder.build()); }
From source file:com.skalski.raspberrycontrol.Custom_WebSocketClient.java
@Override public void onTextMessage(String payload) { Message payload_msg = new Message(); boolean send_message = false; try {//from ww w . ja v a2s. co m JSONObject jsonObj = new JSONObject(payload); if (jsonObj.has(TAG_HAN_GPIOSTATE)) if ((this.ClientHandler != null) && (this.ClientFilter.equals(TAG_HAN_GPIOSTATE))) send_message = true; if (jsonObj.has(TAG_HAN_TEMPSENSORS)) if ((this.ClientHandler != null) && (this.ClientFilter.equals(TAG_HAN_TEMPSENSORS))) send_message = true; if (jsonObj.has(TAG_HAN_PROCESSES)) if ((this.ClientHandler != null) && (this.ClientFilter.equals(TAG_HAN_PROCESSES))) send_message = true; if (jsonObj.has(TAG_HAN_STATISTICS)) if ((this.ClientHandler != null) && (this.ClientFilter.equals(TAG_HAN_STATISTICS))) send_message = true; if (jsonObj.has(TAG_ERROR)) if (this.ClientHandler != null) send_message = true; if (jsonObj.has(TAG_HAN_NOTIFICATION)) { if (Activity_Settings.pref_notifications_disabled(getBaseContext())) { Log.i(LOGTAG, LOGPREFIX + "notification: disabled"); } else { int notification_id; if (Activity_Settings.pref_multiple_notifications_disabled(getBaseContext())) notification_id = 0; else notification_id = (int) System.currentTimeMillis(); Notification new_notification = new Notification.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(jsonObj.getString(TAG_HAN_NOTIFICATION)) .setSmallIcon(R.drawable.ic_launcher).build(); new_notification.defaults |= Notification.DEFAULT_ALL; NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); notificationManager.notify(notification_id, new_notification); Log.i(LOGTAG, LOGPREFIX + "notification: " + notification_id); } } } catch (JSONException e) { Log.e(LOGTAG, LOGPREFIX + "can't parse JSON object"); } if (send_message) { payload_msg.obj = payload; ClientHandler.sendMessage(payload_msg); } }
From source file:com.granita.icloudcalsync.syncadapter.DavSyncAdapter.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override/* ww w . j a va 2 s. c o m*/ public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Log.i(TAG, "Performing sync for authority " + authority); // set class loader for iCal4j ResourceLoader Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); // create httpClient, if necessary httpClientLock.writeLock().lock(); if (httpClient == null) { Log.d(TAG, "Creating new DavHttpClient"); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); httpClient = DavHttpClient.create(); } // prevent httpClient shutdown until we're ready by holding a read lock // acquiring read lock before releasing write lock will downgrade the write lock to a read lock httpClientLock.readLock().lock(); httpClientLock.writeLock().unlock(); // TODO use VCard 4.0 if possible AccountSettings accountSettings = new AccountSettings(getContext(), account); Log.d(TAG, "Server supports VCard version " + accountSettings.getAddressBookVCardVersion()); Exception exceptionToShow = null; // exception to show notification for Intent exceptionIntent = null; // what shall happen when clicking on the exception notification try { // get local <-> remote collection pairs Map<LocalCollection<?>, RemoteCollection<?>> syncCollections = getSyncPairs(account, provider); if (syncCollections == null) Log.i(TAG, "Nothing to synchronize"); else try { for (Map.Entry<LocalCollection<?>, RemoteCollection<?>> entry : syncCollections.entrySet()) new SyncManager(entry.getKey(), entry.getValue()) .synchronize(extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult); } catch (DavException ex) { syncResult.stats.numParseExceptions++; Log.e(TAG, "Invalid DAV response", ex); exceptionToShow = ex; } catch (HttpException ex) { if (ex.getCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "HTTP Unauthorized " + ex.getCode(), ex); syncResult.stats.numAuthExceptions++; // hard error exceptionToShow = ex; exceptionIntent = new Intent(context, AccountActivity.class); exceptionIntent.putExtra(AccountActivity.EXTRA_ACCOUNT, account); } else if (ex.isClientError()) { Log.e(TAG, "Hard HTTP error " + ex.getCode(), ex); syncResult.stats.numParseExceptions++; // hard error exceptionToShow = ex; } else { Log.w(TAG, "Soft HTTP error " + ex.getCode() + " (Android will try again later)", ex); syncResult.stats.numIoExceptions++; // soft error } } catch (LocalStorageException ex) { syncResult.databaseError = true; // hard error Log.e(TAG, "Local storage (content provider) exception", ex); exceptionToShow = ex; } catch (IOException ex) { syncResult.stats.numIoExceptions++; // soft error Log.e(TAG, "I/O error (Android will try again later)", ex); if (ex instanceof SSLException) // always notify on SSL/TLS errors exceptionToShow = ex; } catch (URISyntaxException ex) { syncResult.stats.numParseExceptions++; // hard error Log.e(TAG, "Invalid URI (file name) syntax", ex); exceptionToShow = ex; } } finally { // allow httpClient shutdown httpClientLock.readLock().unlock(); } // show sync errors as notification if (exceptionToShow != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (exceptionIntent == null) exceptionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.WEB_URL_VIEW_LOGS)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, exceptionIntent, 0); Notification.Builder builder = new Notification.Builder(context).setSmallIcon(R.drawable.ic_launcher) .setPriority(Notification.PRIORITY_LOW).setOnlyAlertOnce(true) .setWhen(System.currentTimeMillis()) .setContentTitle(context.getString(R.string.sync_error_title)) .setContentText(exceptionToShow.getLocalizedMessage()).setContentInfo(account.name) .setStyle(new Notification.BigTextStyle() .bigText(account.name + ":\n" + ExceptionUtils.getFullStackTrace(exceptionToShow))) .setContentIntent(contentIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(account.name.hashCode(), builder.build()); } Log.i(TAG, "Sync complete for " + authority); }
From source file:com.hybris.mobile.lib.location.geofencing.service.GeofencingIntentService.java
/** * Send a notification when a geofence is triggered * * @param geofence the geofence triggered * @param notification the notification object * @param geofenceTransition the geofence transition type *//*from ww w . j a v a 2s . c o m*/ protected void sendNotification(Geofence geofence, GeofenceObject.Notification notification, int geofenceTransition) { if (notification != null) { // Notification String notificationContentTitle = notification.getNotificationTitle(); String notificationContentText = notification.getNotificationText(); int notificationIconResId = notification.getNotificationIconResId(); Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle(notificationContentTitle).setContentText(notificationContentText); if (notificationIconResId > 0) { builder.setSmallIcon(notificationIconResId); } try { // Intent on click on the notification if (StringUtils.isNotBlank(notification.getIntentClassDestination())) { Class<?> intentClassDestination = Class.forName(notification.getIntentClassDestination()); // Create an explicit content Intent that starts the Activity defined in intentClassDestination Intent notificationIntent = new Intent(this, intentClassDestination); // Geofence Id to pass to the activity in order to retrieve the object if (notification.getIntentBundle() != null) { GeofenceObject.IntentBundle intentBundle = notification.getIntentBundle(); notificationIntent.putExtra(intentBundle.getKeyName(), intentBundle.getBundle()); // Easter egg :) if (intentBundle.getBundle().getBoolean(GeofencingConstants.EXTRA_PLAY_SOUND)) { MediaPlayer mediaPlayer; if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) { Log.d(TAG, "Playing entering geofence sound"); mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.entering_geofence); } else { Log.d(TAG, "Playing exiting geofence sound"); mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.leaving_geofence); } mediaPlayer.start(); } } PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, geofence.getRequestId().hashCode(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(notificationPendingIntent); } } catch (ClassNotFoundException e) { Log.e(TAG, "Unable to find class " + notification.getIntentClassDestination() + "." + e.getLocalizedMessage()); } // Constructing the Notification and setting the flag to auto remove the notification when the user click on it Notification notificationView; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notificationView = builder.build(); } else { notificationView = builder.getNotification(); } notificationView.flags = Notification.FLAG_AUTO_CANCEL; notificationView.defaults = Notification.DEFAULT_ALL; // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(UUID.randomUUID().toString().hashCode(), notificationView); } else { Log.e(TAG, "Notification empty for Geofence " + geofence); } }