List of usage examples for android.app Notification Notification
@Deprecated public Notification(int icon, CharSequence tickerText, long when)
From source file:edu.stanford.junction.sample.partyware.ImgurUploadService.java
/** * This method uploads an image from the given uri. It does the uploading in * small chunks to make sure it doesn't over run the memory. * // w ww. ja v a2 s . c om * @param uri * image location * @return map containing data from interaction */ private String readPictureDataAndUpload(final Uri uri) { Log.i(this.getClass().getName(), "in readPictureDataAndUpload(Uri)"); try { final AssetFileDescriptor assetFileDescriptor = getContentResolver().openAssetFileDescriptor(uri, "r"); final int totalFileLength = (int) assetFileDescriptor.getLength(); assetFileDescriptor.close(); // Create custom progress notification mProgressNotification = new Notification(R.drawable.icon, getString(R.string.imgur_upload_in_progress), System.currentTimeMillis()); // set as ongoing mProgressNotification.flags |= Notification.FLAG_ONGOING_EVENT; // set custom view to notification mProgressNotification.contentView = generateProgressNotificationView(0, totalFileLength); //empty intent for the notification final Intent progressIntent = new Intent(); final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, progressIntent, 0); mProgressNotification.contentIntent = contentIntent; // add notification to manager mNotificationManager.notify(NOTIFICATION_ID, mProgressNotification); final InputStream inputStream = getContentResolver().openInputStream(uri); final String boundaryString = "Z." + Long.toHexString(System.currentTimeMillis()) + Long.toHexString((new Random()).nextLong()); final String boundary = "--" + boundaryString; final HttpURLConnection conn = (HttpURLConnection) (new URL("http://imgur.com/api/upload.json")) .openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-type", "multipart/form-data; boundary=\"" + boundaryString + "\""); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); conn.setChunkedStreamingMode(CHUNK_SIZE); final OutputStream hrout = conn.getOutputStream(); final PrintStream hout = new PrintStream(hrout); hout.println(boundary); hout.println("Content-Disposition: form-data; name=\"key\""); hout.println("Content-Type: text/plain"); hout.println(); Random rng = new Random(); String key = API_KEYS[rng.nextInt(API_KEYS.length)]; hout.println(key); hout.println(boundary); hout.println("Content-Disposition: form-data; name=\"image\""); hout.println("Content-Transfer-Encoding: base64"); hout.println(); hout.flush(); { final Base64OutputStream bhout = new Base64OutputStream(hrout); final byte[] pictureData = new byte[READ_BUFFER_SIZE_BYTES]; int read = 0; int totalRead = 0; long lastLogTime = 0; while (read >= 0) { read = inputStream.read(pictureData); if (read > 0) { bhout.write(pictureData, 0, read); totalRead += read; if (lastLogTime < (System.currentTimeMillis() - PROGRESS_UPDATE_INTERVAL_MS)) { lastLogTime = System.currentTimeMillis(); Log.d(this.getClass().getName(), "Uploaded " + totalRead + " of " + totalFileLength + " bytes (" + (100 * totalRead) / totalFileLength + "%)"); //make a final version of the total read to make the handler happy final int totalReadFinal = totalRead; mHandler.post(new Runnable() { public void run() { mProgressNotification.contentView = generateProgressNotificationView( totalReadFinal, totalFileLength); mNotificationManager.notify(NOTIFICATION_ID, mProgressNotification); } }); } bhout.flush(); hrout.flush(); } } Log.d(this.getClass().getName(), "Finishing upload..."); // This close is absolutely necessary, this tells the // Base64OutputStream to finish writing the last of the data // (and including the padding). Without this line, it will miss // the last 4 chars in the output, missing up to 3 bytes in the // final output. bhout.close(); Log.d(this.getClass().getName(), "Upload complete..."); mProgressNotification.contentView.setProgressBar(R.id.UploadProgress, totalFileLength, totalRead, false); mNotificationManager.cancelAll(); } hout.println(boundary); hout.flush(); hrout.close(); inputStream.close(); Log.d(this.getClass().getName(), "streams closed, " + "now waiting for response from server"); final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); final StringBuilder rData = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { rData.append(line).append('\n'); } return rData.toString(); } catch (final IOException e) { Log.e(this.getClass().getName(), "Upload failed", e); } return null; }
From source file:uk.org.openseizuredetector.client.SdClientService.java
/** * Show a notification while this service is running. */// w w w.jav a2s. c o m private void showNotification() { Log.v(TAG, "showNotification()"); CharSequence text = "Alarm Client for OpenSeizureDetector Running"; Notification notification = new Notification(R.drawable.star_of_life_24x24, text, System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ClientActivity.class), 0); notification.setLatestEventInfo(this, "Alarm Client for OpenSeizureDetector", text, contentIntent); notification.flags |= Notification.FLAG_NO_CLEAR; mNM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_ID, notification); }
From source file:com.akop.bach.service.XboxLiveServiceClient.java
private void notifyFriends(XboxLiveAccount account, long[] friendsOnline, List<Long> lastFriendsOnline) { NotificationManager mgr = getNotificationManager(); Context context = getContext(); int notificationId = 0x2000000 | ((int) account.getId() & 0xffffff); if (App.getConfig().logToConsole()) { String s = ""; for (Object unr : lastFriendsOnline) s += unr.toString() + ","; App.logv("Currently online (%d): %s", lastFriendsOnline.size(), s); s = "";//ww w.j ava 2s. c o m for (Object unr : friendsOnline) s += unr.toString() + ","; App.logv("New online (%d): %s", friendsOnline.length, s); } if (friendsOnline.length > 0) { int newOnlineCount = 0; for (Object online : friendsOnline) if (!lastFriendsOnline.contains(online)) newOnlineCount++; if (App.getConfig().logToConsole()) App.logv("%d computed new; %d online now; %d online before", newOnlineCount, friendsOnline.length, lastFriendsOnline.size()); if (newOnlineCount > 0) { // Prepare notification objects String tickerTitle; String tickerText; if (friendsOnline.length == 1) { tickerTitle = context.getString(R.string.friend_online); tickerText = context.getString(R.string.notify_friend_online_f, Friends.getGamertag(context, friendsOnline[0]), account.getDescription()); } else { tickerTitle = context.getString(R.string.friends_online); tickerText = context.getString(R.string.notify_friends_online_f, account.getScreenName(), friendsOnline.length, account.getDescription()); } Notification notification = new Notification(R.drawable.xbox_stat_notify_friend, tickerText, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; Intent intent = new Intent(context, FriendList.class); intent.putExtra("account", account); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0); notification.setLatestEventInfo(context, tickerTitle, tickerText, contentIntent); // New users online if (friendsOnline.length > 1) notification.number = friendsOnline.length; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledOnMS = DEFAULT_LIGHTS_ON_MS; notification.ledOffMS = DEFAULT_LIGHTS_OFF_MS; notification.ledARGB = DEFAULT_LIGHTS_COLOR; notification.sound = account.getRingtoneUri(); if (account.isVibrationEnabled()) notification.defaults |= Notification.DEFAULT_VIBRATE; mgr.notify(notificationId, notification); } } else // No unread messages { mgr.cancel(notificationId); } }
From source file:org.fdroid.enigtext.service.KeyCachingService.java
private void foregroundServiceLegacy() { Notification notification = new Notification(R.drawable.icon_cached, getString(R.string.KeyCachingService_textsecure_passphrase_cached), System.currentTimeMillis()); Intent intent = new Intent(this, RoutingActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent launchIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); notification.setLatestEventInfo(getApplicationContext(), getString(R.string.KeyCachingService_passphrase_cached), getString(R.string.KeyCachingService_textsecure_passphrase_cached), launchIntent); stopForeground(true);//ww w . ja va2 s. c o m startForeground(SERVICE_RUNNING_ID, notification); }
From source file:org.droidkit.app.UpdateService.java
private void notifyDownloading(String json) { Intent intent = new Intent(this, UpdateActivity.class); intent.putExtra("downloading", true); intent.putExtra("json", json); String desc = "Downloading " + getString(getApplicationInfo().labelRes); PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0); Notification n = new Notification(android.R.drawable.stat_sys_download, "Downloading update...", System.currentTimeMillis()); n.flags = Notification.FLAG_ONGOING_EVENT; n.contentIntent = pending;/*w w w . ja va 2 s . c o m*/ RemoteViews view = new RemoteViews(getPackageName(), Resources.getId(this, "update_notification", Resources.TYPE_LAYOUT)); view.setTextViewText(Resources.getId(this, "update_title_text", Resources.TYPE_ID), desc); view.setProgressBar(Resources.getId(this, "update_progress_bar", Resources.TYPE_ID), 100, 0, true); view.setImageViewResource(Resources.getId(this, "update_notif_icon", Resources.TYPE_ID), android.R.drawable.stat_sys_download); n.contentView = view; mNotificationManager.notify("Downloading update...", UPDATE_DOWNLOADING_ID, n); }
From source file:com.example.ramap.MainActivity.java
@SuppressWarnings("deprecation") private void Notify(String notificationTitle, String notificationMessage) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); @SuppressWarnings("deprecation") Notification notification = new Notification(R.drawable.ic_check_in, "New Check In", System.currentTimeMillis()); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(MainActivity.this, notificationTitle, notificationMessage, pendingIntent); notificationManager.notify(9999, notification); }
From source file:cm.aptoide.pt.DownloadQueueService.java
private void setFinishedNotification(int apkidHash, String localPath) { String apkid = notifications.get(apkidHash).get("apkid"); int size = Integer.parseInt(notifications.get(apkidHash).get("intSize")); String version = notifications.get(apkidHash).get("version"); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification); contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification); contentView.setTextViewText(R.id.download_notification_name, getString(R.string.finished_download_message) + " " + apkid + " v." + version); contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, size * KBYTES_TO_BYTES, false); Intent onClick = new Intent("pt.caixamagica.aptoide.INSTALL_APK", Uri.parse("apk:" + apkid)); onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt.RemoteInTab"); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.putExtra("localPath", localPath); onClick.putExtra("apkid", apkid); onClick.putExtra("apkidHash", apkidHash); onClick.putExtra("isUpdate", Boolean.parseBoolean(notifications.get(apkid.hashCode()).get("isUpdate"))); /*Changed by Rafael Campos*/ onClick.putExtra("version", notifications.get(apkid.hashCode()).get("version")); Log.d("Aptoide-DownloadQueuService", "finished notification apkidHash: " + apkidHash + " localPath: " + localPath); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0); Notification notification = new Notification(R.drawable.ic_notification, getString(R.string.finished_download_alrt) + " " + apkid, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.contentView = contentView; // Set the info for the notification panel. notification.contentIntent = onClickAction; // notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Send the notification. // We use the position because it is a unique number. We use it later to cancel. notificationManager.notify(apkidHash, notification); // Log.d("Aptoide-DownloadQueueService", "Notification Set"); }
From source file:org.mythdroid.util.UpdateService.java
private void checkMythDroid() { if (MDVer == null) return;//from w w w . j av a2 s . c om Version runningVer; try { runningVer = new Version(getPackageManager().getPackageInfo(getPackageName(), 0).versionName, null); } catch (NameNotFoundException e) { return; } if (runningVer.compareTo(MDVer) >= 0) { LogUtil.debug("Already running latest version of MythDroid"); //$NON-NLS-1$ return; } LogUtil.debug("Version " + MDVer.toString() + //$NON-NLS-1$ " is available (current version is " + runningVer.toString() + ")" //$NON-NLS-1$ //$NON-NLS-2$ ); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final Notification notification = new Notification(R.drawable.logo, Messages.getString("UpdateService.0") + "MythDroid" + //$NON-NLS-1$ //$NON-NLS-2$ Messages.getString("UpdateService.1"), //$NON-NLS-1$ System.currentTimeMillis()); notification.flags = Notification.FLAG_AUTO_CANCEL; final Intent intent = new Intent(MDACTION); intent.putExtra(VER, MDVer.toString()); intent.putExtra(URL, MDVer.url.toString()); notification.setLatestEventInfo(getApplicationContext(), "MythDroid" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$ MDVer.toString() + Messages.getString("UpdateService.1") + //$NON-NLS-1$ Messages.getString("UpdateService.3"), //$NON-NLS-1$ PendingIntent.getBroadcast(this, 0, intent, 0)); nm.notify(CHECKMD, notification); }
From source file:nl.sogeti.android.gpstracker.actions.NameTrack.java
private void startDelayNotification() { int resId = R.string.dialog_routename_title; int icon = R.drawable.ic_maps_indicator_current_position; CharSequence tickerText = getResources().getString(resId); long when = System.currentTimeMillis(); Notification nameNotification = new Notification(icon, tickerText, when); nameNotification.flags |= Notification.FLAG_AUTO_CANCEL; CharSequence contentTitle = getResources().getString(R.string.app_name); CharSequence contentText = getResources().getString(resId); Intent notificationIntent = new Intent(this, NameTrack.class); notificationIntent.setData(mTrackUri); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK); nameNotification.setLatestEventInfo(this, contentTitle, contentText, contentIntent); NotificationManager noticationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); noticationManager.notify(R.layout.namedialog, nameNotification); }
From source file:com.geomoby.geodeals.DemoService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w.j ava2 s.c o m*/ private static void generateNotification(Context context, String message) { if (message.length() > 0) { // Parse the GeoMoby message using the GeoMessage class try { Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonArray Jarray = parser.parse(message).getAsJsonArray(); ArrayList<GeoMessage> alerts = new ArrayList<GeoMessage>(); for (JsonElement obj : Jarray) { GeoMessage gName = gson.fromJson(obj, GeoMessage.class); alerts.add(gName); } // Prepare Notification and pass the GeoMessage to an Extra NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Intent i = new Intent(context, CustomNotification.class); i.putParcelableArrayListExtra("GeoMessage", (ArrayList<GeoMessage>) alerts); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); // Read from the /assets directory Resources resources = context.getResources(); AssetManager assetManager = resources.getAssets(); try { InputStream inputStream = assetManager.open("geomoby.properties"); Properties properties = new Properties(); properties.load(inputStream); String push_icon = properties.getProperty("push_icon"); int icon = resources.getIdentifier(push_icon, "drawable", context.getPackageName()); int not_title = resources.getIdentifier("notification_title", "string", context.getPackageName()); int not_text = resources.getIdentifier("notification_text", "string", context.getPackageName()); int not_ticker = resources.getIdentifier("notification_ticker", "string", context.getPackageName()); // Manage notifications differently according to Android version if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(icon).setContentTitle(context.getResources().getText(not_title)) .setContentText(context.getResources().getText(not_text)) .setTicker(context.getResources().getText(not_ticker)) .setContentIntent(pendingIntent).setAutoCancel(true); builder.setDefaults(Notification.DEFAULT_ALL); //Vibrate, Sound and Led // Because the ID remains unchanged, the existing notification is updated. notificationManager.notify(notifyID, builder.build()); } else { Notification notification = new Notification(icon, context.getResources().getText(not_text), System.currentTimeMillis()); //Setting Notification Flags notification.defaults |= Notification.DEFAULT_ALL; notification.flags |= Notification.FLAG_AUTO_CANCEL; //Set the Notification Info notification.setLatestEventInfo(context, context.getResources().getText(not_text), context.getResources().getText(not_ticker), pendingIntent); //Send the notification // Because the ID remains unchanged, the existing notification is updated. notificationManager.notify(notifyID, notification); } } catch (IOException e) { System.err.println("Failed to open geomoby property file"); e.printStackTrace(); } } catch (JsonParseException e) { Log.i(TAG, "This is not a GeoMoby notification"); throw new RuntimeException(e); } } }