List of usage examples for android.app Notification Notification
@Deprecated public Notification(int icon, CharSequence tickerText, long when)
From source file:net.sf.asap.PlayerService.java
public void run() { // read file/*from w w w .j a v a 2 s . c om*/ 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:net.geniecode.ttr.ScheduleReceiver.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") private void setNotification(Context context) { ScrollingText = context.getString(R.string.schedule_postponed_scroll); NotificationText = context.getString(R.string.schedule_postponed_notify); // Trigger a notification that, when clicked, will activate airplane mode mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, ActivateFlightMode.class), PendingIntent.FLAG_CANCEL_CURRENT); Notification notification;//w w w .j a va 2s .c om if (android.os.Build.VERSION.SDK_INT >= 11) { Notification.Builder builder = new Notification.Builder(context); builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher).setTicker(ScrollingText) .setWhen(System.currentTimeMillis()).setAutoCancel(true).setOnlyAlertOnce(true) .setDefaults(Notification.DEFAULT_LIGHTS).setContentTitle(context.getText(R.string.app_name)) .setContentText(NotificationText); if (android.os.Build.VERSION.SDK_INT >= 16) { notification = builder.build(); } else { notification = builder.getNotification(); } } else { notification = new Notification(R.drawable.ic_launcher, ScrollingText, System.currentTimeMillis()); notification.setLatestEventInfo(context, context.getText(R.string.app_name), NotificationText, contentIntent); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_LIGHTS; } mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.keithandthegirl.services.download.DownloadService.java
@SuppressWarnings("deprecation") private void sendNotification(String description) { mContentTitle = description;// w w w . j a va 2s . c o m long when = System.currentTimeMillis(); notificationId = (int) when; mNotification = new Notification(android.R.drawable.stat_sys_download, getResources().getString(R.string.app_name), when); Intent notificationIntent = new Intent(); mContentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); mNotification.setLatestEventInfo(this, getResources().getString(R.string.app_name), mContentTitle, mContentIntent); mNotification.flags = Notification.FLAG_ONGOING_EVENT; mNotificationManager.notify(notificationId, mNotification); }
From source file:ca.mcgill.hs.serv.LogFileUploaderService.java
@Override public synchronized void onStart(final Intent intent, final int startId) { // Update the file list updateFileList();//from w w w . j a va 2s.c om // If there are no files, return. if (fileList.size() == 0 && !started) { makeToast(getResources().getString(R.string.uploader_no_new_files), Toast.LENGTH_SHORT); return; } // If it was already started, return. Else, continue. if (started) { return; } // At this point we consider the service to be started. started = true; registerReceiver(wifiOnlyPrefChanged, new IntentFilter(WIFI_ONLY_CHANGED_INTENT)); registerReceiver(autoPrefChanged, new IntentFilter(AUTO_UPLOAD_CHANGED_INTENT)); wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiInfo = wifiMgr.getConnectionInfo(); // Register completion receiver registerReceiver(completionReceiver, new IntentFilter(UPLOAD_COMPLETE_INTENT)); // Connect to a network setUpConnection(); notificationMgr = (NotificationManager) getSystemService(NOTIFICATION_STRING); notificationMgr.cancel(NOTIFICATION_ID); final int icon = R.drawable.notification_icon; final String tickerText = getResources().getString(R.string.notification_ticker); final String contentTitle = getResources().getString(R.string.notification_upload_title); final String contentText = getResources().getString(R.string.notification_upload_text); final Notification n = new Notification(icon, tickerText, System.currentTimeMillis()); final Intent i = new Intent(this, HSService.class); n.setLatestEventInfo(this, contentTitle, contentText, PendingIntent.getActivity(this.getBaseContext(), 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); notificationMgr.notify(NOTIFICATION_ID, n); filesUploaded = 0; uploadFiles(); }
From source file:org.linphone.LinphoneService.java
@Override public void onCreate() { super.onCreate(); theLinphone = this; // Dump some debugging information to the logs Hacks.dumpDeviceInformation();//from ww w . ja v a2s.c o m addCallListner(); // tryTogetLastReceive(); // tryTogetLastRequest(); tryKeepOnline(); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotification = new Notification(R.drawable.status_level, "", System.currentTimeMillis()); mNotification.iconLevel = IC_LEVEL_ORANGE; mNotification.flags |= Notification.FLAG_ONGOING_EVENT; Intent notificationIntent = new Intent(this, MainViewActivity.class); mNofificationContentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); mNotification.setLatestEventInfo(this, NOTIFICATION_TITLE, "", mNofificationContentIntent); mNotificationManager.notify(NOTIFICATION_ID, mNotification); mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mAudioManager = ((AudioManager) getSystemService(Context.AUDIO_SERVICE)); mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); try { copyAssetsFromPackage(); mLinphoneCore = LinphoneCoreFactory.instance().createLinphoneCore(this, LINPHONE_RC, LINPHONE_FACTORY_RC, null); mLinphoneCore.setPlaybackGain(3); mLinphoneCore.setRing(null); try { initFromConf(); } catch (LinphoneException e) { Log.w(TAG, "no config ready yet"); } TimerTask lTask = new TimerTask() { @Override public void run() { mLinphoneCore.iterate(); } }; mTimer.scheduleAtFixedRate(lTask, 0, 100); IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON); lFilter.addAction(Intent.ACTION_SCREEN_OFF); registerReceiver(mKeepAliveMgrReceiver, lFilter); } catch (Exception e) { Log.e(TAG, "Cannot start linphone", e); } }
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);//from ww w. j ava 2 s . co m }
From source file:com.samknows.measurement.test.TestExecutor.java
@SuppressWarnings("deprecation") public void showNotification(String message) { String title = tc.getString(R.string.ntf_title); NotificationManager manager = (NotificationManager) tc.getSystemService(Context.NOTIFICATION_SERVICE); Notification n = new Notification(R.drawable.icon, message, System.currentTimeMillis()); PendingIntent intent = PendingIntent.getService(tc.getServiceContext(), Constants.RC_NOTIFICATION, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT); n.setLatestEventInfo(tc.getServiceContext(), title, message, intent); manager.notify(Constants.NOTIFICATION_ID, n); }
From source file:com.tingtingapps.securesms.service.KeyCachingService.java
private void foregroundServiceLegacy() { Notification notification = new Notification(com.tingtingapps.securesms.R.drawable.icon_cached, getString(com.tingtingapps.securesms.R.string.KeyCachingService_textsecure_passphrase_cached), System.currentTimeMillis()); notification.setLatestEventInfo(getApplicationContext(), getString(com.tingtingapps.securesms.R.string.KeyCachingService_passphrase_cached), getString(com.tingtingapps.securesms.R.string.KeyCachingService_textsecure_passphrase_cached), buildLaunchIntent());/*from w w w .j a va 2 s . c o m*/ notification.tickerText = null; stopForeground(true); startForeground(SERVICE_RUNNING_ID, notification); }
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 www. j av a2s . co m nm.notify(112344, notification); }
From source file:uk.org.openseizuredetector.SdServer.java
/** * Show a notification while this service is running. *//*from w ww .j ava 2 s . com*/ private void showNotification() { Log.v(TAG, "showNotification()"); CharSequence text = "OpenSeizureDetector Server Running"; Notification notification = new Notification(R.drawable.star_of_life_24x24, text, System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); notification.setLatestEventInfo(this, "OpenSeizureDetector Server", text, contentIntent); notification.flags |= Notification.FLAG_NO_CLEAR; mNM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_ID, notification); }