List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:com.afrozaar.jazzfestreporting.ResumableUpload.java
/** * Uploads user selected video in the project folder to the user's YouTube account using OAuth2 * for authentication.//from www.ja va2s . co m */ public static String upload(YouTube youtube, final InputStream fileInputStream, final long fileSize, final Uri mFileUri, final String path, final Context context) { final NotificationManager notifyManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); Intent notificationIntent = new Intent(context, ReviewActivity.class); notificationIntent.setData(mFileUri); notificationIntent.setAction(Intent.ACTION_VIEW); Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(path, Thumbnails.MICRO_KIND); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentTitle(context.getString(R.string.youtube_upload)) .setContentText(context.getString(R.string.youtube_upload_started)) .setSmallIcon(R.drawable.ic_stat_device_access_video).setContentIntent(contentIntent) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(thumbnail)); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); String videoId = null; try { // Add extra information to the video before uploading. Video videoObjectDefiningMetadata = new Video(); /* * Set the video to public, so it is available to everyone (what most people want). This is * actually the default, but I wanted you to see what it looked like in case you need to set * it to "unlisted" or "private" via API. */ VideoStatus status = new VideoStatus(); status.setPrivacyStatus("public"); videoObjectDefiningMetadata.setStatus(status); // We set a majority of the metadata with the VideoSnippet object. VideoSnippet snippet = new VideoSnippet(); /* * The Calendar instance is used to create a unique name and description for test purposes, so * you can see multiple files being uploaded. You will want to remove this from your project * and use your own standard names. */ Calendar cal = Calendar.getInstance(); snippet.setTitle("Test Upload via Java on " + cal.getTime()); snippet.setDescription( "Video uploaded via YouTube Data API V3 using the Java library " + "on " + cal.getTime()); // Set your keywords. snippet.setTags(Arrays.asList(Constants.DEFAULT_KEYWORD, Upload.generateKeywordFromPlaylistId(Constants.UPLOAD_PLAYLIST))); // Set completed snippet to the video object. videoObjectDefiningMetadata.setSnippet(snippet); InputStreamContent mediaContent = new InputStreamContent(VIDEO_FILE_FORMAT, new BufferedInputStream(fileInputStream)); mediaContent.setLength(fileSize); /* * The upload command includes: 1. Information we want returned after file is successfully * uploaded. 2. Metadata we want associated with the uploaded video. 3. Video file itself. */ YouTube.Videos.Insert videoInsert = youtube.videos().insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent); // Set the upload type and add event listener. MediaHttpUploader uploader = videoInsert.getMediaHttpUploader(); /* * Sets whether direct media upload is enabled or disabled. True = whole media content is * uploaded in a single request. False (default) = resumable media upload protocol to upload * in data chunks. */ uploader.setDirectUploadEnabled(false); MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() { public void progressChanged(MediaHttpUploader uploader) throws IOException { switch (uploader.getUploadState()) { case INITIATION_STARTED: builder.setContentText(context.getString(R.string.initiation_started)) .setProgress((int) fileSize, (int) uploader.getNumBytesUploaded(), false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); break; case INITIATION_COMPLETE: builder.setContentText(context.getString(R.string.initiation_completed)) .setProgress((int) fileSize, (int) uploader.getNumBytesUploaded(), false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); break; case MEDIA_IN_PROGRESS: builder.setContentTitle(context.getString(R.string.youtube_upload) + (int) (uploader.getProgress() * 100) + "%") .setContentText(context.getString(R.string.upload_in_progress)) .setProgress((int) fileSize, (int) uploader.getNumBytesUploaded(), false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); break; case MEDIA_COMPLETE: builder.setContentTitle(context.getString(R.string.yt_upload_completed)) .setContentText(context.getString(R.string.upload_completed)) // Removes the progress bar .setProgress(0, 0, false); notifyManager.notify(UPLOAD_NOTIFICATION_ID, builder.build()); case NOT_STARTED: Log.d(this.getClass().getSimpleName(), context.getString(R.string.upload_not_started)); break; } } }; uploader.setProgressListener(progressListener); // Execute upload. Video returnedVideo = videoInsert.execute(); Log.d(TAG, "Video upload completed"); videoId = returnedVideo.getId(); Log.d(TAG, String.format("videoId = [%s]", videoId)); } catch (final GooglePlayServicesAvailabilityIOException availabilityException) { Log.e(TAG, "GooglePlayServicesAvailabilityIOException", availabilityException); notifyFailedUpload(context, context.getString(R.string.cant_access_play), notifyManager, builder); } catch (UserRecoverableAuthIOException userRecoverableException) { Log.i(TAG, String.format("UserRecoverableAuthIOException: %s", userRecoverableException.getMessage())); requestAuth(context, userRecoverableException); } catch (IOException e) { Log.e(TAG, "IOException", e); notifyFailedUpload(context, context.getString(R.string.please_try_again), notifyManager, builder); } return videoId; }
From source file:com.chilliworks.chillisource.core.LocalNotificationReceiver.java
/** * Called when a local notification broad cast is received. Funnels the notification * into the app if open or into the notification bar if not * // w ww .jav a2s . c o m * @author Steven Hendrie * * @param The context. * @param The intent. */ @SuppressWarnings("deprecation") @Override public void onReceive(Context in_context, Intent in_intent) { //evaluate whether or not the main engine activity is in the foreground boolean isAppInForeground = false; if (CSApplication.get() != null && CSApplication.get().isActive() == true) { isAppInForeground = true; } //if the main engine activity is in the foreground, simply pass the //notification into it. Otherwise display a notification. if (isAppInForeground == true) { final Intent intent = new Intent(in_intent.getAction()); Bundle mapParams = in_intent.getExtras(); Iterator<String> iter = mapParams.keySet().iterator(); while (iter.hasNext()) { String strKey = iter.next(); intent.putExtra(strKey, mapParams.get(strKey).toString()); } LocalNotificationNativeInterface localNotificationNI = (LocalNotificationNativeInterface) CSApplication .get().getSystem(LocalNotificationNativeInterface.InterfaceID); if (localNotificationNI != null) { localNotificationNI.onNotificationReceived(intent); } } else { //aquire a wake lock if (s_wakeLock != null) { s_wakeLock.release(); } PowerManager pm = (PowerManager) in_context.getSystemService(Context.POWER_SERVICE); s_wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "NotificationWakeLock"); s_wakeLock.acquire(); //pull out the information from the intent Bundle params = in_intent.getExtras(); CharSequence title = params.getString(k_paramNameTitle); CharSequence text = params.getString(k_paramNameBody); int intentId = params.getInt(LocalNotification.k_paramNameNotificationId); int paramSize = params.size(); String[] keys = new String[paramSize]; String[] values = new String[paramSize]; Iterator<String> iter = params.keySet().iterator(); int paramNumber = 0; while (iter.hasNext()) { keys[paramNumber] = iter.next(); values[paramNumber] = params.get(keys[paramNumber]).toString(); ++paramNumber; } Intent openAppIntent = new Intent(in_context, CSActivity.class); openAppIntent.setAction("android.intent.action.MAIN"); openAppIntent.addCategory("android.intent.category.LAUNCHER"); openAppIntent.putExtra(k_appOpenedFromNotification, true); openAppIntent.putExtra(k_arrayOfKeysName, keys); openAppIntent.putExtra(k_arrayOfValuesName, values); openAppIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent sContentIntent = PendingIntent.getActivity(in_context, intentId, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIconBitmap = null; int LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify_large"); //Use small icon if no large icon if (LargeIconID == 0) { LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify"); } if (LargeIconID > 0) { largeIconBitmap = BitmapFactory.decodeResource(in_context.getResources(), LargeIconID); } Notification notification = new NotificationCompat.Builder(in_context).setContentTitle(title) .setContentText(text) .setSmallIcon(ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify")) .setLargeIcon(largeIconBitmap).setContentIntent(sContentIntent).build(); NotificationManager notificationManager = (NotificationManager) in_context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(intentId, notification); Toast.makeText(in_context, text, Toast.LENGTH_LONG).show(); } }
From source file:com.chilliworks.chillisource.core.GCMService.java
private void generateNotification(Context context, HashMap<String, String> inParams) { //if the application is active then pass this information on to the application. if (CSApplication.get() != null && CSApplication.get().isActive() == true) { //build the array of keys and values int dwNumEntries = inParams.size(); String[] astrKeys = new String[dwNumEntries]; String[] astrValues = new String[dwNumEntries]; int dwCount = 0; for (String strKey : inParams.keySet()) { astrKeys[dwCount] = strKey;/*from w w w . jav a 2 s. co m*/ astrValues[dwCount] = inParams.get(strKey); dwCount++; } // Send this to the native side of the engine. mNativeInterface.OnRemoteNotificationReceived(astrKeys, astrValues); } // Otherwise display a notification. else { String strTitle = context.getString(R.getId(context, R.Type.STRING, "app_name")); String strMessage = inParams.get("message"); Intent notificationIntent = new Intent(context, CSActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); int smallIconId = 0; if (R.doesExist(context, R.Type.DRAWABLE, "ic_stat_notify") == true) { smallIconId = R.getId(context, R.Type.DRAWABLE, "ic_stat_notify"); } int largeIconId = smallIconId; if (R.doesExist(context, R.Type.DRAWABLE, "ic_stat_notify_large") == true) { largeIconId = R.getId(context, R.Type.DRAWABLE, "ic_stat_notify_large"); } Bitmap largeIconBitmap = null; if (largeIconId > 0) { largeIconBitmap = BitmapFactory.decodeResource(context.getResources(), largeIconId); } Notification notification = new NotificationCompat.Builder(context).setContentTitle(strTitle) .setContentText(strMessage).setSmallIcon(smallIconId).setLargeIcon(largeIconBitmap) .setContentIntent(intent).build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification); } }
From source file:com.anrlabs.locationreminder.GeoFenceReceiver.java
private void sendNotification(String title) { Intent notificationIntent = new Intent(context, ShowReminder.class); notificationIntent.putExtra("notificationId", strinIds[0]); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(ShowReminder.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); //int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff); // PendingIntent notificationPendingIntent = PendingIntent.getActivity(context, iUniqueId, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setContentText("Click here to open app") .setContentIntent(notificationPendingIntent).setTicker("You have a new Reminder"); builder.setAutoCancel(true);//from www. ja va 2 s . c om pref = context.getSharedPreferences("alert", 0); if (pref.getBoolean("check", false)) { long[] vibrate = { 0, 100, 200, 200, 200, 200 }; builder.setVibrate(vibrate); } else builder.setDefaults(Notification.DEFAULT_SOUND); // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(0, builder.build()); }
From source file:com.magnet.mmx.client.MMXWakeupIntentService.java
private void invokeNotificationForPush(GCMPayload payload) { // Launch the activity with action=MAIN, category=DEFAULT. Make sure that // it has DEFAULT category declared in AndroidManifest.xml intent-filter. PendingIntent intent = PendingIntent.getActivity(this.getApplicationContext(), 0, new Intent(Intent.ACTION_MAIN).setPackage(this.getPackageName()) .addCategory(Intent.CATEGORY_DEFAULT) // it is redundant .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED), PendingIntent.FLAG_UPDATE_CURRENT); // If title is not specified, use the app name (compatible with iOS push notification) String title = (payload.getTitle() == null) ? this.getApplicationInfo().name : payload.getTitle(); Notification.Builder noteBuilder = new Notification.Builder(this).setContentIntent(intent) .setAutoCancel(true).setWhen(System.currentTimeMillis()).setContentTitle(title) .setContentText(payload.getBody()); if (payload.getSound() != null) { // TODO: cannot handle custom sound yet; use notification ring tone. noteBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); }/*from w w w . j a va 2s.c om*/ if (payload.getIcon() != null) { noteBuilder.setSmallIcon( this.getResources().getIdentifier(payload.getIcon(), "drawable", this.getPackageName())); } else { noteBuilder.setSmallIcon(this.getApplicationInfo().icon); } if (payload.getBadge() != null) { noteBuilder.setNumber(payload.getBadge()); } NotificationManager noteMgr = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); noteMgr.notify(sNoteId++, noteBuilder.build()); }
From source file:com.anthonykeane.speedzone.ActivityRecognitionIntentService.java
/** * Post a notification to the user. The notification prompts the user to click it to * open the device's GPS settings//from w ww . j a v a 2 s . c om */ private void sendNotification() { // Create a notification builder that's compatible with platforms >= version 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()); // Set the title, text, and icon builder.setContentTitle(getString(R.string.app_name)); builder.setContentText(getString(R.string.NotificationText)); builder.setSmallIcon(R.drawable.ic_launcher); //builder.setContentIntent(WhatToDoWhenNotificationIsClicked()); // Get an instance of the Notification Manager NotificationManager notifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Build the notification and post it notifyManager.notify(0, builder.build()); }
From source file:com.chilliworks.chillisource.googleplay.core.GCMService.java
private void generateNotification(Context context, HashMap<String, String> inParams) { //if the application is active then pass this information on to the application. if (CSApplication.get() != null && CSApplication.get().isActive() == true) { //build the array of keys and values int dwNumEntries = inParams.size(); String[] astrKeys = new String[dwNumEntries]; String[] astrValues = new String[dwNumEntries]; int dwCount = 0; for (String strKey : inParams.keySet()) { astrKeys[dwCount] = strKey;/*from w w w . j ava 2 s.c o m*/ astrValues[dwCount] = inParams.get(strKey); dwCount++; } // Send this to the native side of the engine. mNativeInterface.OnRemoteNotificationReceived(astrKeys, astrValues); } // Otherwise display a notification. else { String strTitle = context.getString(ResourceHelper.GetDynamicResourceIDForField(context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_STRING, "app_name")); String strMessage = inParams.get("message"); Intent notificationIntent = new Intent(context, CSActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Bitmap largeIconBitmap = null; int largeIconID = ResourceHelper.GetDynamicResourceIDForField(context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify_large"); //If no large icon then use the small icon if (largeIconID == 0) { largeIconID = ResourceHelper.GetDynamicResourceIDForField(context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify"); } if (largeIconID > 0) { largeIconBitmap = BitmapFactory.decodeResource(context.getResources(), largeIconID); } Notification notification = new NotificationCompat.Builder(context).setContentTitle(strTitle) .setContentText(strMessage) .setSmallIcon(ResourceHelper.GetDynamicResourceIDForField(context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify")) .setLargeIcon(largeIconBitmap).setContentIntent(intent).build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification); } }
From source file:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java
private void notifyDebug() { final Resources res = getResources(); String contentTitle = "Debug Notification"; String contentText;// ww w. j a va2 s. co m long currentTime = TimeUtils.getUTCTime(); long matchStart = TimeUtils.getUTCTime() + 60000; int minutesLeft = (int) (matchStart - currentTime + 59000) / 60000; if (minutesLeft < 2 && minutesLeft >= 0) { minutesLeft = 1; } if (minutesLeft < 0) { contentText = "debugNotification"; } else { contentText = "debugNotification"; } 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).setPriority(Notification.PRIORITY_DEFAULT) .setAutoCancel(true); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notifBuilder.build()); }
From source file:com.bufarini.reminders.AlarmReceiver.java
private void showNotification(Context context, Intent intent) { Intent snoozeIntent = new Intent(context, NotificationActivity.class); snoozeIntent.putExtras(intent.getExtras()); snoozeIntent.putExtra("notificaton action", "snooze"); PendingIntent snoozePendingIntent = PendingIntent.getActivity(context, 0, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent doneIntent = new Intent(context, NotificationActivity.class); doneIntent.putExtras(intent.getExtras()); doneIntent.putExtra("notificaton action", "done"); doneIntent.putExtra("task", intent.getSerializableExtra("task")); PendingIntent donePendingIntent = PendingIntent.getActivity(context, 1, doneIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent resultIntent = new Intent(context, Reminders.class); resultIntent.putExtra("action", "view task"); resultIntent.putExtra("task", intent.getSerializableExtra("task")); resultIntent.setFlags(/*w w w . ja v a2s . co m*/ Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true) .setSmallIcon(R.drawable.ic_action_alarms) .setContentTitle(context.getResources().getString(R.string.alarmPopupTitle1)) .setContentIntent(resultPendingIntent) .addAction(R.drawable.ic_action_alarms, "Snooze", snoozePendingIntent) .addAction(R.drawable.ic_action_done, "Done", donePendingIntent) .setContentText(intent.getExtras().getString(NotificationUtils.TITLE)); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); int notificationId = NotificationUtils.getNotificationId(intent.getExtras().getLong(NotificationUtils.ID)); notificationManager.notify(notificationId, builder.build()); }
From source file:com.otaupdater.utils.KernelInfo.java
public void showUpdateNotif(Context ctx) { Intent mainInent = new Intent(ctx, TabDisplay.class); mainInent.setAction(TabDisplay.KERNEL_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_KERNEL_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_kernel)); builder.setTicker(ctx.getString(R.string.notif_text_kernel)); 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.KERNEL_NOTIF_ID, builder.build()); }