List of usage examples for android.app Notification setLatestEventInfo
@Deprecated public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent)
From source file:de.taxilof.UulmLoginAgent.java
/** * notify the User in Statusbar// w ww.j a v a 2 s .c o m */ private void notify(String subject, String message, boolean errorIcon) { // build notification with notifyString Notification notifyDetails; mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (errorIcon) { notifyDetails = new Notification(R.drawable.icon_red, subject, System.currentTimeMillis()); } else { notifyDetails = new Notification(R.drawable.icon, subject, System.currentTimeMillis()); } PendingIntent myIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); notifyDetails.setLatestEventInfo(context, subject, message, myIntent); notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); }
From source file:net.sf.asap.PlayerService.java
public void run() { // read file/*from w ww . ja v a2 s .c o m*/ String filename = uri.getPath(); byte[] module = new byte[ASAPInfo.MAX_MODULE_LENGTH]; int moduleLen; try { InputStream is; switch (uri.getScheme()) { case "file": if (Util.isZip(filename)) { String zipFilename = filename; filename = uri.getFragment(); is = new ZipInputStream(zipFilename, filename); } else is = new FileInputStream(filename); break; case "http": is = httpGet(uri); break; default: throw new FileNotFoundException(uri.toString()); } moduleLen = Util.readAndClose(is, module); } catch (IOException ex) { showError(R.string.error_reading_file); return; } // load file try { asap.load(filename, module, moduleLen); info = asap.getInfo(); switch (song) { case SONG_DEFAULT: song = info.getDefaultSong(); break; case SONG_LAST: song = info.getSongs() - 1; break; default: break; } playSong(); } catch (Exception ex) { showError(R.string.invalid_file); return; } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Player.class), 0); String title = info.getTitleOrFilename(); Notification notification = new Notification(R.drawable.icon, title, System.currentTimeMillis()); notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.setLatestEventInfo(this, title, info.getAuthor(), contentIntent); startForegroundCompat(NOTIFICATION_ID, notification); // playback int channelConfig = info.getChannels() == 1 ? AudioFormat.CHANNEL_CONFIGURATION_MONO : AudioFormat.CHANNEL_CONFIGURATION_STEREO; int bufferLen = AudioTrack.getMinBufferSize(ASAP.SAMPLE_RATE, channelConfig, AudioFormat.ENCODING_PCM_16BIT) >> 1; if (bufferLen < 16384) bufferLen = 16384; final byte[] byteBuffer = new byte[bufferLen << 1]; final short[] shortBuffer = new short[bufferLen]; audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, ASAP.SAMPLE_RATE, channelConfig, AudioFormat.ENCODING_PCM_16BIT, bufferLen << 1, AudioTrack.MODE_STREAM); audioTrack.play(); for (;;) { synchronized (this) { if (bufferLen < shortBuffer.length || isPaused()) { try { wait(); } catch (InterruptedException ex) { } } if (stop) { audioTrack.stop(); return; } } synchronized (asap) { int pos = seekPosition; if (pos >= 0) { seekPosition = -1; try { asap.seek(pos); } catch (Exception ex) { } } bufferLen = asap.generate(byteBuffer, byteBuffer.length, ASAPSampleFormat.S16_L_E) >> 1; } for (int i = 0; i < bufferLen; i++) shortBuffer[i] = (short) ((byteBuffer[i << 1] & 0xff) | byteBuffer[i << 1 | 1] << 8); audioTrack.write(shortBuffer, 0, bufferLen); } }
From source file:org.openplans.rcavl.LocationService.java
public void realStart(Intent intent) { String url = intent.getStringExtra("pingUrl"); String email = intent.getStringExtra("email"); String password = intent.getStringExtra("password"); pingInterval = intent.getIntExtra("pingInterval", 60); Notification notification = new Notification(R.drawable.icon, "Ridepilot Mobile", System.currentTimeMillis()); Intent appIntent = new Intent(this, RCAVL.class); appIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, appIntent, 0); notification.setLatestEventInfo(this, "Ridepilot Mobile", "connected", pi); notification.flags |= Notification.FLAG_NO_CLEAR; startForeground(66786, notification); thread = new LocationServiceThread(url, email, password); new Thread(thread).start(); }
From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java
@SuppressWarnings("deprecation") public Notification createNotification(Bundle settings, JSONObject obj) { // notifications[i] = api.normalizeAPI({ // 'string': { // mandatory: ['title', 'body'], // defaults: {'icon':'icon'} // },//from www . j a va 2s . c om // // 'number': { // mandatory: ['id', 'timeMillisSince1970'], // // the number of ms after which we start prioritising more recent // things above you. // defaults: {'epsilon': 1000 * 60 * 24 * 365} // }, // // 'boolean': { // defaults: { // 'vibrate': false, // 'sound': false // } // } int icon = settings.getInt("notification_icon", -1); if (icon == -1) { Log.e(C.TAG, "Need a notification_icon resource in the meta-data of LocalNotificationsAlarmReceiver"); return null; } Notification n = new Notification(); n.icon = icon; n.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; long alarmTime = obj.optLong("timeMillisSince1970"); long displayTime = obj.optLong("displayTimestamp", alarmTime); n.when = displayTime; n.tickerText = obj.optString("body"); n.setLatestEventInfo(mContext, obj.optString("title"), obj.optString("body"), null); if (obj.optBoolean("vibrate")) { n.defaults |= Notification.DEFAULT_VIBRATE; } if (obj.optBoolean("sound")) { n.defaults |= Notification.DEFAULT_SOUND; } String uriString = settings.getString("content_uri_prefix"); if (uriString == null) { Log.e(C.TAG, "Need a content_uri_prefix in the meta-data of LocalNotificationsAlarmReceiver"); return null; } if (uriString.contains("%d")) { uriString = String.format(uriString, obj.optInt("id")); } Uri uri = Uri.parse(uriString); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(uri); n.contentIntent = PendingIntent.getActivity(mContext, 23, intent, PendingIntent.FLAG_ONE_SHOT); return n; }
From source file:com.tweetlanes.android.service.BackgroundService.java
private void showNotification() { nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // In this sample, we'll use the same text for the ticker and the expanded notification //CharSequence text = getText(R.string.service_started); // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.ic_launcher, "Message preview here", System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, HomeActivity.class), 0); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, "Count = " + mCount, "Full message here", contentIntent); // Send the notification. // We use a layout id because it is a unique number. We use it later to cancel. nm.notify(112344, notification);// ww w. java 2s . c o m }
From source file:com.survey.android.c2dm.GcmNotificationReceiver.java
@SuppressWarnings("deprecation") private void sendNotification(Intent intent) { final String testResult = intent.getStringExtra("message"); final String surveyId = intent.getStringExtra("survey_id"); try {//from w w w . ja v a 2s . c om String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(ns); String mDrawableName = "c2dm_icon"; int icon = this.getResources().getIdentifier(mDrawableName, "drawable", Prefs.PACKAGE); CharSequence tickerText = "Survey notification"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); CharSequence contentTitle = "Survey notification"; int NOTIFICATION_ID = 1; Intent notificationIntent = new Intent(this, com.survey.android.view.themed.NotificationActivity.class); notificationIntent.putExtra("notification_id", NOTIFICATION_ID); notificationIntent.putExtra("survey_id", surveyId); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT + PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, contentTitle, testResult, contentIntent); mNotificationManager.notify(NOTIFICATION_ID, notification); } catch (Exception e) { e.printStackTrace(); } }
From source file:github.madmarty.madsonic.util.Util.java
/** * Resolves the default text color for notifications. * * Based on http://stackoverflow.com/questions/4867338/custom-notification-layouts-and-text-colors/7320604#7320604 *///ww w . j a v a 2 s .c om @SuppressWarnings("deprecation") private static Pair<Integer, Integer> getNotificationTextColors(Context context) { if (NOTIFICATION_TEXT_COLORS.getFirst() == null && NOTIFICATION_TEXT_COLORS.getSecond() == null) { try { Notification notification = new Notification(); String title = "title"; String content = "content"; notification.setLatestEventInfo(context, title, content, null); LinearLayout group = new LinearLayout(context); ViewGroup event = (ViewGroup) notification.contentView.apply(context, group); findNotificationTextColors(event, title, content); group.removeAllViews(); } catch (Exception x) { LOG.warn("Failed to resolve notification text colors.", x); } } return NOTIFICATION_TEXT_COLORS; }
From source file:com.shafiq.mytwittle.service.BackgroundService.java
private void showNotification() { nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // In this sample, we'll use the same text for the ticker and the // expanded notification // CharSequence text = getText(R.string.service_started); // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.ic_launcher, "Message preview here", System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this // notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, HomeActivity.class), 0); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, "Count = " + mCount, "Full message here", contentIntent); // Send the notification. // We use a layout id because it is a unique number. We use it later to // cancel./*from w w w.j av a2s . com*/ nm.notify(112344, notification); }