Java Code Examples for android.app.Notification
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project agit, under directory /agit/src/main/java/com/madgag/agit/operation/lifecycle/.
Source file: RepoNotifications.java

public void notifyCompletionWith(OpNotification completionNotification){ Log.i(TAG,"notifyCompletion() " + this + " : "+ completionNotification); Notification cn=createNotificationWith(completionNotification); cn.flags|=FLAG_AUTO_CANCEL; notificationManager.notify(completionNotificationId,cn); }
Example 2
From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/helper/.
Source file: NotificationHelper.java

public void showRecordingNotification(){ long time=System.currentTimeMillis(); Notification notification=new Notification(R.drawable.ic_media_record,aircastingIsRecording,time); notification.flags&=~Notification.FLAG_AUTO_CANCEL; Intent notificationIntent=new Intent(context,SoundTraceActivity.class); PendingIntent pendingIntent=PendingIntent.getActivity(context,REQUEST_ANY,notificationIntent,EMPTY_FLAGS); notification.setLatestEventInfo(context,aircastingIsRecording,"",pendingIntent); notificationManager.notify(RECORDING_ID,notification); }
Example 3
From project AlarmApp-Android, under directory /src/org/alarmapp/util/.
Source file: NotificationUtil.java

public static void notifyUser(Context c,int id,String title,String message,Class<?> cls,Bundle bundle,Uri sound,int defaults){ String ns=Context.NOTIFICATION_SERVICE; NotificationManager notificationManager=(NotificationManager)c.getSystemService(ns); Notification notification=createNotification(title,sound); Intent notificationIntent=new Intent(c,cls); if (bundle != null) notificationIntent.putExtras(bundle); PendingIntent contentIntent=PendingIntent.getActivity(c,0,notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT); notification.setLatestEventInfo(c,title,message,contentIntent); notification.defaults=defaults; notificationManager.notify(id,notification); }
Example 4
From project android-pedometer, under directory /src/name/bagi/levente/pedometer/.
Source file: StepService.java

/** * Show a notification while this service is running. */ private void showNotification(){ CharSequence text=getText(R.string.app_name); Notification notification=new Notification(R.drawable.ic_notification,null,System.currentTimeMillis()); notification.flags=Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; Intent pedometerIntent=new Intent(); pedometerIntent.setComponent(new ComponentName(this,Pedometer.class)); pedometerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent=PendingIntent.getActivity(this,0,pedometerIntent,0); notification.setLatestEventInfo(this,text,getText(R.string.notification_subtitle),contentIntent); mNM.notify(R.string.app_name,notification); }
Example 5
From project android-shuffle, under directory /client/src/org/dodgybits/shuffle/android/synchronisation/tracks/service/.
Source file: SynchronizationService.java

private void createNotification(){ int icon=R.drawable.shuffle_icon; CharSequence tickerText=this.getText(R.string.app_name); long when=System.currentTimeMillis(); Notification notification=new Notification(icon,tickerText,when); Intent notificationIntent=new Intent(this,SynchronizeActivity.class); notification.contentIntent=PendingIntent.getActivity(this,0,notificationIntent,0); notification.contentView=contentView; mNotificationManager.notify(NOTIFICATION_ID,notification); }
Example 6
From project Android-Terminal-Emulator, under directory /src/jackpal/androidterm/.
Source file: TermService.java

@Override public void onCreate(){ compat=new ServiceForegroundCompat(this); mTermSessions=new SessionList(); Notification notification=new Notification(R.drawable.ic_stat_service_notification_icon,getText(R.string.service_notify_text),System.currentTimeMillis()); notification.flags|=Notification.FLAG_ONGOING_EVENT; Intent notifyIntent=new Intent(this,Term.class); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent=PendingIntent.getActivity(this,0,notifyIntent,0); notification.setLatestEventInfo(this,getText(R.string.application_terminal),getText(R.string.service_notify_text),pendingIntent); compat.startForeground(RUNNING_NOTIFICATION,notification); Log.d(TermDebug.LOG_TAG,"TermService started"); return; }
Example 7
From project android-vpn-server, under directory /src/com/android/server/vpn/.
Source file: VpnService.java

void update(long now){ String title=getNotificationTitle(true); Notification n=new Notification(R.drawable.vpn_connected,title,mStartTime); n.setLatestEventInfo(mContext,title,getConnectedNotificationMessage(now),prepareNotificationIntent()); n.flags|=Notification.FLAG_NO_CLEAR; n.flags|=Notification.FLAG_ONGOING_EVENT; enableNotification(n); }
Example 8
From project android-xbmcremote, under directory /src/org/xbmc/android/remote/presentation/activity/.
Source file: NowPlayingNotificationManager.java

public void showNotification(String artist,String title,String text,int icon){ Notification notification=buildNotification(artist + " - " + title,text,icon); final String ns=Context.NOTIFICATION_SERVICE; NotificationManager notificationManager=(NotificationManager)mContext.getSystemService(ns); notificationManager.notify(NOW_PLAYING_ID,notification); }
Example 9
From project androidannotations, under directory /HelloWorldEclipse/src/com/googlecode/androidannotations/helloworldeclipse/.
Source file: MyActivity.java

@UiThread(delay=2000) void showNotificationsDelayed(){ Notification notification=new Notification(R.drawable.icon,"Hello !",0); PendingIntent contentIntent=PendingIntent.getActivity(this,0,new Intent(),0); notification.setLatestEventInfo(getApplicationContext(),"My notification","Hello World!",contentIntent); notificationManager.notify(1,notification); }
Example 10
From project android_packages_apps_cmparts, under directory /src/com/cyanogenmod/cmparts/activities/led/.
Source file: PackageSettingsActivity.java

@Override public void colorUpdate(int color){ final Notification notification=new Notification(); notification.flags|=Notification.FLAG_SHOW_LIGHTS; notification.ledOnMS=500; notification.ledOffMS=0; notification.ledARGB=color; prepareSettingsForTest(); mHandler.removeCallbacks(mCancelTestRunnable); mNM.notify(NOTIFICATION_ID,notification); mHandler.postDelayed(mCancelTestRunnable,1000); }
Example 11
From project android_packages_apps_Exchange, under directory /src/com/android/exchange/.
Source file: CalendarSyncEnabler.java

/** * Show the "Exchange calendar added" notification. * @param emailAddresses space delimited list of email addresses of Exchange accounts. It'llbe shown on the notification. */ void showNotificationForTest(String emailAddresses){ PendingIntent launchCalendarPendingIntent=PendingIntent.getActivity(mContext,0,createLaunchCalendarIntent(),0); String tickerText=mContext.getString(R.string.notification_exchange_calendar_added); Notification n=new Notification(R.drawable.stat_notify_calendar,tickerText,System.currentTimeMillis()); n.setLatestEventInfo(mContext,tickerText,emailAddresses,launchCalendarPendingIntent); n.flags=Notification.FLAG_AUTO_CANCEL; NotificationManager nm=(NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID_EXCHANGE_CALENDAR_ADDED,n); }
Example 12
From project android_packages_apps_phone, under directory /src/com/android/phone/.
Source file: NotificationMgr.java

/** * Shows the "data disconnected due to roaming" notification, which appears when you lose data connectivity because you're roaming and you have the "data roaming" feature turned off. */ void showDataDisconnectedRoaming(){ if (DBG) log("showDataDisconnectedRoaming()..."); Intent intent=new Intent(mContext,Settings.class); Notification notification=new Notification(mContext,android.R.drawable.stat_sys_warning,null,System.currentTimeMillis(),mContext.getString(R.string.roaming),mContext.getString(R.string.roaming_reenable_message),intent); mNotificationMgr.notify(DATA_DISCONNECTED_ROAMING_NOTIFICATION,notification); }
Example 13
From project android_packages_apps_Superuser, under directory /src/com/noshufou/android/su/util/.
Source file: Util.java

public static void showOutdatedNotification(Context context){ if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(Preferences.OUTDATED_NOTIFICATION,true)) { NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification=new Notification(R.drawable.stat_su,context.getString(R.string.notif_outdated_ticker),System.currentTimeMillis()); PendingIntent contentIntent=PendingIntent.getActivity(context,0,new Intent(context,UpdaterActivity.class),0); notification.setLatestEventInfo(context,context.getString(R.string.notif_outdated_title),context.getString(R.string.notif_outdated_text),contentIntent); notification.flags|=Notification.FLAG_AUTO_CANCEL; nm.notify(UpdaterService.NOTIFICATION_ID,notification); } }
Example 14
From project Anki-Android, under directory /src/com/tomgibara/android/veecheck/util/.
Source file: DefaultNotifier.java

@Override protected Notification createNotification(PendingIntent intent){ Notification n=new Notification(iconId,context.getText(tickerId),System.currentTimeMillis()); n.contentIntent=intent; n.flags=Notification.FLAG_AUTO_CANCEL; n.setLatestEventInfo(context,context.getText(titleId),context.getText(messageId),intent); return n; }
Example 15
From project AnySoftKeyboard, under directory /src/com/anysoftkeyboard/ui/tutorials/.
Source file: TutorialsProvider.java

public synchronized static void showNotificationIcon(Context context,IntentToLaunch notificationData){ final NotificationManager mngr=((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)); Notification notification=new Notification(notificationData.NotificationIcon,context.getText(notificationData.NotificationText),System.currentTimeMillis()); PendingIntent contentIntent=PendingIntent.getActivity(context,0,notificationData.IntentToStart,0); notification.setLatestEventInfo(context,context.getText(notificationData.NotificationTitle),context.getText(notificationData.NotificationText),contentIntent); notification.defaults=0; notification.flags=Notification.FLAG_AUTO_CANCEL; mngr.notify(notificationData.NotificationID,notification); }
Example 16
From project Backyard-Brains-Android-App, under directory /src/com/backyardbrains/audio/.
Source file: AudioService.java

/** * Toggle a notification that this service is running. * @param show show if true, hide otherwise. * @see android.app.Notification * @see NotificationManager#notify() */ private void showNotification(boolean show){ if (show) { CharSequence text=getText(R.string.mic_thread_running); Notification not=new Notification(R.drawable.ic_launcher_byb,text,System.currentTimeMillis()); PendingIntent contentIntent=PendingIntent.getActivity(this,0,new Intent(this,BackyardAndroidActivity.class),0); not.setLatestEventInfo(this,"Backyard Brains",text,contentIntent); mNM.notify(NOTIFICATION,not); } else { if (mNM != null) { mNM.cancel(NOTIFICATION); } } }
Example 17
From project Binaural-Beats, under directory /src/com/ihunda/android/binauralbeat/.
Source file: BBeat.java

private void _start_notification(String programName){ Notification notification=new Notification(R.drawable.icon,getString(R.string.notif_started),System.currentTimeMillis()); Context context=getApplicationContext(); CharSequence contentTitle=getString(R.string.notif_started); CharSequence contentText=getString(R.string.notif_descr,programName); Intent notificationIntent=this.getIntent(); PendingIntent contentIntent=PendingIntent.getActivity(this,0,notificationIntent,0); notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent); notification.flags|=Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; mNotificationManager.notify(NOTIFICATION_STARTED,notification); }
Example 18
From project Birthday-widget, under directory /Birthday/src/main/java/cz/krtinec/birthday/.
Source file: NotificationSender.java

protected static void fireBirthdayAlert(Context ctx,Event c,Long when){ String label=formatLabel(ctx,c); Notification n=new Notification(R.drawable.icon,label,when); n.flags=n.flags | Notification.FLAG_AUTO_CANCEL; n.defaults=Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS; Intent i=new Intent(ctx,Birthday.class); PendingIntent pendingIntent=PendingIntent.getActivity(ctx,NOTIFY_CODE,i,PendingIntent.FLAG_CANCEL_CURRENT); n.setLatestEventInfo(ctx,label,formatMessage(ctx,c),pendingIntent); NotificationManager manager=(NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE); manager.notify("Birthday",(int)c.getContactId(),n); }
Example 19
From project Birthdays, under directory /src/com/rexmenpara/birthdays/.
Source file: BirthdaysActivity.java

private void calendarSynced(){ NotificationManager.getInstance().cancel(Constants.APP_ID); Notification notification=new Notification(R.drawable.toolbar,"Calendar Sync complete.",System.currentTimeMillis()); Intent intent=new Intent(getApplicationContext(),BirthdaysActivity.class); notification.setLatestEventInfo(BirthdaysActivity.this,"Birthdays","Calendar synchronization complete",PendingIntent.getActivity(BirthdaysActivity.this.getBaseContext(),0,intent,PendingIntent.FLAG_CANCEL_CURRENT)); notification.flags=Notification.FLAG_AUTO_CANCEL; NotificationManager.getInstance().notify(Constants.APP_ID,notification); }
Example 20
From project BombusLime, under directory /src/org/bombusim/lime/.
Source file: NotificationMgr.java

public void showOnlineNotification(boolean online){ if (!serviceIcon) return; int icon=((online) ? R.drawable.ic_launcher : R.drawable.ic_launcher_gray); CharSequence title=context.getText(R.string.app_name); CharSequence message=context.getText((online) ? R.string.presence_online : R.string.presence_offline); Notification notification=new Notification(icon,title,System.currentTimeMillis()); PendingIntent contentIntent=PendingIntent.getActivity(context,0,new Intent("org.bombusim.lime",null,context,RosterActivity.class),0); notification.setLatestEventInfo(context,title,message,contentIntent); notification.flags|=Notification.FLAG_NO_CLEAR; notification.flags|=Notification.FLAG_ONGOING_EVENT; mNM.notify(NOTIFICATION_ONLINE,notification); }
Example 21
From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/.
Source file: BookCatalogueApp.java

/** * Show a notification while this app is running. * @param title * @param message */ public static void showNotification(int id,String title,String message,Intent i){ CharSequence text=message; Notification notification=new Notification(R.drawable.ic_stat_logo,text,System.currentTimeMillis()); notification.flags|=Notification.FLAG_AUTO_CANCEL; PendingIntent contentIntent=PendingIntent.getActivity(context,0,i,0); notification.setLatestEventInfo(context,title,text,contentIntent); mNotifier.notify(id,notification); }
Example 22
From project bookmarktodesktop-android-application, under directory /src/be/vbsteven/bmtodesk/.
Source file: BackgroundSharingService.java

/** * shows the progress notification */ private void showProgress(){ Notification n=new Notification(R.drawable.icon,"Sending bookmark to server...",System.currentTimeMillis()); Intent i=new Intent(this,MainActivity.class); PendingIntent contentIntent=PendingIntent.getActivity(this,1,i,0); n.setLatestEventInfo(this,"Bookmark to Desktop","Sending bookmark to server...",contentIntent); nManager.notify(2,n); }
Example 23
From project btmidi, under directory /BluetoothMidi/src/com/noisepages/nettoyeur/bluetooth/midi/.
Source file: BluetoothMidiService.java

/** * Attempts to connect to the given Bluetooth device with foreground privileges. * @param addr String representation of the MAC address of the Bluetooth device * @param intent intent to be wrapped in a pending intent and fired when the user selects the notification * @param description description of the notification * @throws IOException */ public void connect(String addr,Intent intent,String description) throws IOException { connect(addr); PendingIntent pi=PendingIntent.getActivity(getApplicationContext(),0,intent,0); Notification notification=new Notification(R.drawable.din5,TAG,System.currentTimeMillis()); notification.setLatestEventInfo(this,TAG,description,pi); notification.flags|=Notification.FLAG_ONGOING_EVENT; startForeground(ID,notification); }
Example 24
From project cicada, under directory /cicada/src/org/cicadasong/cicada/.
Source file: CicadaService.java

private void startForeground(){ String notificationTitle=getString(R.string.notification_title); String notificationBody=getString(R.string.notification_body); Notification notification=new Notification(R.drawable.statusbar,notificationTitle,0); PendingIntent contentIntent=PendingIntent.getActivity(this,0,new Intent(this,Cicada.class),0); notification.setLatestEventInfo(getApplicationContext(),notificationTitle,notificationBody,contentIntent); notification.flags|=Notification.FLAG_FOREGROUND_SERVICE; startForeground(1,notification); }
Example 25
From project connectbot, under directory /src/sk/vx/connectbot/service/.
Source file: ConnectionNotifier.java

protected Notification newNotification(Context context){ Notification notification=new Notification(); notification.icon=R.drawable.notification_icon; notification.when=System.currentTimeMillis(); return notification; }
Example 26
From project COSsettings, under directory /src/com/cyanogenmod/cmparts/activities/led/.
Source file: PackageSettingsActivity.java

@Override public void colorUpdate(int color){ final Notification notification=new Notification(); notification.flags|=Notification.FLAG_SHOW_LIGHTS; notification.ledOnMS=500; notification.ledOffMS=0; notification.ledARGB=color; prepareSettingsForTest(); mHandler.removeCallbacks(mCancelTestRunnable); mNM.notify(NOTIFICATION_ID,notification); mHandler.postDelayed(mCancelTestRunnable,1000); }
Example 27
From project cw-advandroid, under directory /Broadcast/Ordered/src/com/commonsware/android/ordered/.
Source file: NoticeReceiver.java

@Override public void onReceive(Context context,Intent intent){ NotificationManager mgr=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification note=new Notification(R.drawable.stat_notify_chat,"Yoo-hoo! Wake up!",System.currentTimeMillis()); PendingIntent i=PendingIntent.getActivity(context,0,new Intent(context,OrderedActivity.class),0); note.setLatestEventInfo(context,"You Care About This!","...but not enough to keep the activity running",i); mgr.notify(NOTIFY_ME_ID,note); }
Example 28
From project cw-android, under directory /Notifications/FakePlayer/src/com/commonsware/android/fakeplayerfg/.
Source file: PlayerService.java

private void play(String playlist,boolean useShuffle){ if (!isPlaying) { Log.w(getClass().getName(),"Got to play()!"); isPlaying=true; Notification note=new Notification(R.drawable.stat_notify_chat,"Can you hear the music?",System.currentTimeMillis()); Intent i=new Intent(this,FakePlayer.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi=PendingIntent.getActivity(this,0,i,0); note.setLatestEventInfo(this,"Fake Player","Now Playing: \"Ummmm, Nothing\"",pi); note.flags|=Notification.FLAG_NO_CLEAR; startForeground(1337,note); } }
Example 29
From project cwac-updater, under directory /demo/src/com/commonsware/cwac/updater/demo/.
Source file: UpdaterDemoActivity.java

ConfirmationStrategy buildPreDownloadConfirmationStrategy(){ Notification n=new Notification(android.R.drawable.stat_notify_chat,"Update availalble",System.currentTimeMillis()); n.setLatestEventInfo(this,"Update Available","Click to download the update!",null); n.flags|=Notification.FLAG_AUTO_CANCEL; return (new NotificationConfirmationStrategy(n)); }
Example 30
From project DeskSMS, under directory /DeskSMS/src/com/koushikdutta/desktopsms/.
Source file: ServiceHelper.java

static void createAuthenticationNotification(Context context){ NotificationManager n=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification=new Notification(R.drawable.icon,context.getString(R.string.authentification_notification),System.currentTimeMillis()); notification.contentView=new RemoteViews(context.getPackageName(),R.layout.notification); Intent intent=new Intent(context,MainActivity.class); intent.putExtra("relogin",true); notification.contentIntent=PendingIntent.getActivity(context,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK); n.cancel(444); n.notify(444,notification); }
Example 31
From project DigitbooksExamples, under directory /DigitbooksExamples/src/fr/digitbooks/android/examples/chapitre02/.
Source file: SimpleService.java

/** * Show a notification. */ private void showNotification(String text){ final int icon=android.R.drawable.stat_notify_error; Notification notification=new Notification(icon,text,System.currentTimeMillis()); final Intent intent=new Intent(this,SimpleServiceActivity.class); PendingIntent contentIntent=PendingIntent.getActivity(this,0,intent,0); notification.setLatestEventInfo(this,"Service simple",text,contentIntent); mNotificationManager.notify(NOTIFICATION_ID,notification); }
Example 32
From project Diktofon, under directory /app/src/kaljurand_at_gmail_dot_com/diktofon/service/.
Source file: DiktofonService.java

/** * @param tickerText Ticker text (shown briefly) * @param contentText Content text (shown when the notification is pulled down) * @param intent Intent to be launched if notification is clicked * @param flags Notification flags * @return Notification object */ protected Notification createNotification(int icon,CharSequence tickerText,CharSequence contentText,Intent intent,int flags){ CharSequence contentTitle=getString(R.string.app_name); Notification notification=new Notification(icon,tickerText,System.currentTimeMillis()); notification.flags=flags; PendingIntent contentIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this,contentTitle,contentText,contentIntent); return notification; }
Example 33
private void notifyUser(String json){ Intent intent=new Intent(this,UpdateActivity.class); intent.putExtra("json",json); String desc="Update available for " + getString(getApplicationInfo().labelRes); PendingIntent pending=PendingIntent.getActivity(this,0,intent,0); Notification n=new Notification(android.R.drawable.stat_sys_download_done,"Update available",System.currentTimeMillis()); n.setLatestEventInfo(this,"Update Available",desc,pending); mNotificationManager.notify("Update Available",UPDATE_SERVICE_ID,n); }
Example 34
From project FBReaderJ, under directory /src/org/geometerplus/android/fbreader/network/.
Source file: BookDownloaderService.java

private Notification createDownloadFinishNotification(File file,String title,boolean success){ final ZLResource resource=getResource(); final String tickerText=success ? resource.getResource("tickerSuccess").getValue() : resource.getResource("tickerError").getValue(); final String contentText=success ? resource.getResource("contentSuccess").getValue() : resource.getResource("contentError").getValue(); final Notification notification=new Notification(android.R.drawable.stat_sys_download_done,tickerText,System.currentTimeMillis()); notification.flags|=Notification.FLAG_AUTO_CANCEL; final Intent intent=success ? getFBReaderIntent(file) : new Intent(); final PendingIntent contentIntent=PendingIntent.getActivity(this,0,intent,0); notification.setLatestEventInfo(getApplicationContext(),title,contentText,contentIntent); return notification; }
Example 35
public static void showNotification(Context context,Intent intent,String title,String body,int drawableId){ NotificationManager manager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification=new Notification(drawableId,body,System.currentTimeMillis()); notification.flags=Notification.FLAG_AUTO_CANCEL; notification.defaults=Notification.DEFAULT_SOUND; if (intent == null) { intent=new Intent(context,FileViewActivity.class); } PendingIntent contentIntent=PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_ONE_SHOT); notification.setLatestEventInfo(context,title,body,contentIntent); manager.notify(drawableId,notification); }
Example 36
From project friendica-for-android, under directory /mw-android-friendica-01/src/de/wikilab/android/friendica01/.
Source file: FileUploadService.java

private void showSuccessMsg(Context ctx){ NotificationManager mNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); int icon=R.drawable.arrow_up; CharSequence tickerText="Upload succeeded!"; long when=System.currentTimeMillis(); Notification notification=new Notification(icon,tickerText,when); notification.flags|=Notification.FLAG_AUTO_CANCEL; Context context=getApplicationContext(); PendingIntent nullIntent=PendingIntent.getActivity(context,0,new Intent(),0); notification.setLatestEventInfo(context,tickerText,"Click to dismiss",nullIntent); mNotificationManager.notify(UPLOAD_SUCCESS_ID,notification); }
Example 37
/** * Tell the OS and user we are now doing an important background operation * @param tickerMsg * @param notificationText */ public void startForeground(String tickerMsg,String notificationText){ int icon=android.R.drawable.stat_sys_download; long when=System.currentTimeMillis(); Notification notification=new Notification(icon,tickerMsg,when); Context context=getApplicationContext(); CharSequence contentTitle="Gaggle"; CharSequence contentText=notificationText; Intent notificationIntent=new Intent(this,TopActivity.class); PendingIntent contentIntent=PendingIntent.getActivity(this,0,notificationIntent,0); notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent); startForegroundGlue(NOTIFICATION_ID,notification); }
Example 38
From project gast-lib, under directory /app/src/root/gast/playground/location/.
Source file: ProximityAlertBroadcastReceiver.java

private void displayNotification(Context context,String message){ NotificationManager notificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent pi=PendingIntent.getActivity(context,0,new Intent(),0); Notification notification=new Notification(R.drawable.icon,message,System.currentTimeMillis()); notification.setLatestEventInfo(context,"GAST","Proximity Alert",pi); notificationManager.notify(NOTIFICATION_ID,notification); }
Example 39
From project GCM-Demo, under directory /gcm/samples/gcm-demo-client/src/com/google/android/gcm/demo/app/.
Source file: GCMIntentService.java

/** * Issues a notification to inform the user that server has sent a message. */ private static void generateNotification(Context context,String message){ int icon=R.drawable.ic_stat_gcm; long when=System.currentTimeMillis(); NotificationManager notificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification=new Notification(icon,message,when); String title=context.getString(R.string.app_name); Intent notificationIntent=new Intent(context,DemoActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent=PendingIntent.getActivity(context,0,notificationIntent,0); notification.setLatestEventInfo(context,title,message,intent); notification.flags|=Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0,notification); }
Example 40
From project Gibberbot, under directory /src/info/guardianproject/otr/app/im/plugin/xmpp/.
Source file: ServerTrustManager.java

private void showToolbarNotification(String title,String notifyMsg,int notifyId,int icon,int flags,Intent nIntent) throws Exception { NotificationManager mNotificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); CharSequence tickerText=notifyMsg; long when=System.currentTimeMillis(); Notification notification=new Notification(icon,tickerText,when); if (flags > 0) { notification.flags|=flags; } CharSequence contentTitle=context.getString(R.string.app_name) + ": " + title; CharSequence contentText=notifyMsg; PendingIntent contentIntent=PendingIntent.getActivity(context,0,nIntent,0); notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent); mNotificationManager.notify(notifyId,notification); }
Example 41
From project gobandroid, under directory /src/org/ligi/gobandroid_hd/ui/.
Source file: GobandroidNotifications.java

public static void addGoLinkNotification(Context context,String golink){ NotificationManager notificationManager=(NotificationManager)context.getSystemService(Activity.NOTIFICATION_SERVICE); Notification notification=new Notification(R.drawable.ic_launcher,"The Go Game you reviewed",System.currentTimeMillis()); Intent notificationIntent=new Intent(context,GoLinkLoadActivity.class); notificationIntent.setData(Uri.parse(golink)); PendingIntent pendingIntent=PendingIntent.getActivity(context,0,notificationIntent,0); notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE + Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(context,"The Go Game you reviewed",golink,pendingIntent); notificationManager.notify(GOLINK_NOTIFICATION_ID,notification); }
Example 42
From project HapiPodcastJ, under directory /src/info/xuluan/podcast/service/.
Source file: PlayerService.java

private void notifyStatus(){ String tickerText=mItem == null ? "player" : mItem.title; Notification notification=new Notification(R.drawable.notify_player,tickerText,0); notification.flags|=Notification.FLAG_ONGOING_EVENT; PendingIntent contentIntent=PendingIntent.getActivity(this,0,new Intent(this,PlayerActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra("moodimg",R.drawable.notify_player),PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this,tickerText,null,contentIntent); mNotificationManager.notify(R.layout.audio_player,notification); }
Example 43
From project hiofenigma-android, under directory /opentimer/src/edu/killerud/kitchentimer/.
Source file: CountdownService.java

private void showAlarmFinishedNotification(){ NotificationManager nm=(NotificationManager)getSystemService(android.app.Activity.NOTIFICATION_SERVICE); Notification notification=new Notification(R.drawable.icon_notification,getString(R.string.notification),System.currentTimeMillis()); Intent resumeActivity=new Intent(this,OpenTimerActivity.class); resumeActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); notification.setLatestEventInfo(this,getString(R.string.notification_title),getString(R.string.notification),PendingIntent.getActivity(this,0,resumeActivity,0)); notification.defaults|=Notification.DEFAULT_LIGHTS; notification.defaults|=Notification.FLAG_INSISTENT; notification.defaults|=Notification.FLAG_AUTO_CANCEL; nm.notify(1,notification); }
Example 44
From project IOCipherServer, under directory /src/info/guardianproject/iocipher/server/.
Source file: WebServerService.java

private void startNotification(){ Notification notice=new Notification(R.drawable.iocipher,"Active: " + mIpAddress,System.currentTimeMillis()); Intent intent=new Intent(WebServerService.this,IOCipherServerActivity.class); PendingIntent pendIntent=PendingIntent.getActivity(WebServerService.this,0,intent,0); notice.setLatestEventInfo(WebServerService.this,"IOCipherServer","Active: " + mIpAddress,pendIntent); notice.flags|=Notification.FLAG_NO_CLEAR; startForeground(mPort,notice); }
Example 45
From project jamendo-android, under directory /src/com/teleca/jamendo/service/.
Source file: DownloadService.java

private void displayNotifcation(DownloadJob job){ String notificationMessage=job.getPlaylistEntry().getTrack().getName() + " - " + job.getPlaylistEntry().getAlbum().getArtistName(); Notification notification=new Notification(android.R.drawable.stat_sys_download_done,notificationMessage,System.currentTimeMillis()); PendingIntent contentIntent=PendingIntent.getActivity(this,0,new Intent(this,DownloadActivity.class),0); notification.setLatestEventInfo(this,getString(R.string.downloaded),notificationMessage,contentIntent); notification.flags|=Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(DOWNLOAD_NOTIFY_ID,notification); }
Example 46
From project keepassdroid, under directory /src/com/keepassdroid/.
Source file: EntryActivity.java

private Notification getNotification(String intentText,int descResId){ String desc=getString(descResId); Notification notify=new Notification(R.drawable.notify,desc,System.currentTimeMillis()); Intent intent=new Intent(intentText); PendingIntent pending=PendingIntent.getBroadcast(this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT); notify.setLatestEventInfo(this,getString(R.string.app_name),desc,pending); return notify; }
Example 47
@Override public void onPostExecute(Boolean result){ if (result) { NotificationManager nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification notification=new Notification(R.drawable.as_statusbar,getString(R.string.newversion_ticker_text),System.currentTimeMillis()); PendingIntent contentIntent=PendingIntent.getActivity(LastFm.this,0,new Intent(Intent.ACTION_VIEW,Uri.parse(mUpdateURL)),0); notification.setLatestEventInfo(LastFm.this,getString(R.string.newversion_info_title),getString(R.string.newversion_info_text),contentIntent); nm.notify(12345,notification); } }
Example 48
/** * Display a notification containing the given string. */ public static void generateNotification(Context context,String message){ int icon=R.drawable.status_icon; long when=System.currentTimeMillis(); Notification notification=new Notification(icon,message,when); notification.setLatestEventInfo(context,"C2DM Example",message,PendingIntent.getActivity(context,0,null,PendingIntent.FLAG_CANCEL_CURRENT)); notification.flags|=Notification.FLAG_AUTO_CANCEL; SharedPreferences settings=Util.getSharedPreferences(context); int notificatonID=settings.getInt("notificationID",0); NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(notificatonID,notification); SharedPreferences.Editor editor=settings.edit(); editor.putInt("notificationID",++notificatonID % 32); editor.commit(); }
Example 49
From project LoL-Chat, under directory /src/com/rei/lolchat/service/.
Source file: BeemChatManager.java

/** * Set a notification of a new chat. * @param chat The chat to access by the notification * @param msgBody the body of the new message */ private void notifyNewChat(Contact c,String msgBody){ CharSequence tickerText=""; try { tickerText=mService.getBind().getRoster().getContact(c.getName()).getName(); } catch ( RemoteException e) { e.printStackTrace(); } Notification notification=new Notification(com.rei.lolchat.R.drawable.ic_stat_lol,tickerText,System.currentTimeMillis()); notification.flags=Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(mService,tickerText,msgBody,makeChatIntent(c)); mService.sendNotification(c.getJID().hashCode(),notification); }
Example 50
From project maven-android-plugin-samples, under directory /apidemos-android-10/application/src/main/java/com/example/android/apis/app/.
Source file: AlarmService_Service.java

/** * Show a notification while this service is running. */ private void showNotification(){ CharSequence text=getText(R.string.alarm_service_started); Notification notification=new Notification(R.drawable.stat_sample,text,System.currentTimeMillis()); PendingIntent contentIntent=PendingIntent.getActivity(this,0,new Intent(this,AlarmService.class),0); notification.setLatestEventInfo(this,getText(R.string.alarm_service_label),text,contentIntent); mNM.notify(R.string.alarm_service_started,notification); }
Example 51
From project MIT-Mobile-for-Android, under directory /src/edu/mit/mitmobile2/alerts/.
Source file: C2DMReceiver.java

protected void notifyUser(Context context,String statusBarText,String alarmTitle,String alarmText,int iconResID,PendingIntent pendingIntent){ NotificationManager notificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); long curTime=System.currentTimeMillis(); Notification notify=new Notification(iconResID,statusBarText,curTime); notify.setLatestEventInfo(context,alarmTitle,alarmText,pendingIntent); notify.flags=Notification.FLAG_AUTO_CANCEL; notify.defaults=Notification.DEFAULT_ALL; notificationManager.notify((int)curTime,notify); }
Example 52
From project adg-android, under directory /src/com/analysedesgeeks/android/os_service/.
Source file: PodcastPlaybackService.java

/** * Starts playback of a previously opened file. */ public void play(){ mAudioManager.registerMediaButtonEventReceiver(new ComponentName(this.getPackageName(),MediaButtonIntentReceiver.class.getName())); if (mPlayer.isInitialized()) { mPlayer.start(); final int icon=R.drawable.ic_notification; final CharSequence tickerText=description; final String title=getString(R.string.analyseDesGeeks); final long when=System.currentTimeMillis(); final Notification notification=new Notification(icon,tickerText,when); notification.flags|=Notification.FLAG_ONGOING_EVENT; final Intent contentIntent=new Intent(this,MainActivity.class); final PendingIntent appIntent=PendingIntent.getActivity(this,0,contentIntent,0); notification.setLatestEventInfo(this,title,description,appIntent); startForeground(PLAYBACKSERVICE_STATUS,notification); if (!mIsSupposedToBePlaying) { mIsSupposedToBePlaying=true; hasPlayed=true; } } }
Example 53
From project aksunai, under directory /src/org/androidnerds/app/aksunai/service/.
Source file: ChatManager.java

/** * MessageListeners */ public void onNewMessageList(String serverName,String messageListName){ if (AppConstants.DEBUG) Log.d(AppConstants.CHAT_TAG,"onNewMessageList(" + serverName + ", "+ messageListName+ ")"); mChatActivity.createChat(serverName,messageListName); Server s=mConnections.get(serverName); MessageList ml=s.mMessageLists.get(messageListName); ml.setOnNewMessageListener(this); boolean notify=mPrefs.getBoolean("pref_notification_bar",false); if (notify && ml.mType == MessageList.Type.PRIVATE) { Intent i=new Intent(this,ChatActivity.class); i.putExtra("server",serverName); i.putExtra("chat",messageListName); PendingIntent pending=PendingIntent.getActivity(this,0,i,0); Notification n=new Notification(android.R.drawable.stat_notify_chat,"New Message From " + messageListName,System.currentTimeMillis()); n.setLatestEventInfo(this,"Aksunai","New Message From " + messageListName,pending); String ringtone=mPrefs.getString("notification-ringtone",""); if (ringtone.equals("")) { n.defaults|=Notification.DEFAULT_SOUND; } else { n.sound=Uri.parse(ringtone); } if (mPrefs.getBoolean("pref_notification_vibrate",false)) { n.vibrate=new long[]{100,250,100,250}; } mNotificationManager.notify(R.string.notify_new_private_chat,n); } }
Example 54
From project alljoyn_java, under directory /samples/android/chat/src/org/alljoyn/bus/sample/chat/.
Source file: AllJoynService.java

/** * Our onCreate() method is called by the Android appliation framework when the service is first created. We spin up a background thread to handle any long-lived requests (pretty much all AllJoyn calls that involve communication with remote processes) that need to be done and insinuate ourselves into the list of observers of the model so we can get event notifications. */ public void onCreate(){ Log.i(TAG,"onCreate()"); startBusThread(); mChatApplication=(ChatApplication)getApplication(); mChatApplication.addObserver(this); CharSequence title="AllJoyn"; CharSequence message="Chat Channel Hosting Service."; Intent intent=new Intent(this,TabWidget.class); PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,0); Notification notification=new Notification(R.drawable.icon,null,System.currentTimeMillis()); notification.setLatestEventInfo(this,title,message,pendingIntent); notification.flags|=Notification.DEFAULT_SOUND | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; Log.i(TAG,"onCreate(): startForeground()"); startForeground(NOTIFICATION_ID,notification); mBackgroundHandler.connect(); mBackgroundHandler.startDiscovery(); }
Example 55
From project and-bible, under directory /AndBible/src/net/bible/android/device/.
Source file: ProgressNotificationManager.java

public void initialise(){ Log.i(TAG,"Initializing"); workListener=new WorkListener(){ @Override public void workProgressed( WorkEvent ev){ final Progress prog=ev.getJob(); final int done=prog.getWork(); if (prog.isFinished() || done % 5 == 0) { String status=StringUtils.left(prog.getJobName(),50) + SharedConstants.LINE_SEPARATOR; if (!StringUtils.isEmpty(prog.getSectionName()) && !prog.getSectionName().equalsIgnoreCase(prog.getJobName())) { status+=prog.getSectionName(); } final Notification notification=findOrCreateNotification(prog); notification.contentView.setProgressBar(R.id.status_progress,100,done,false); notification.contentView.setTextViewText(R.id.status_text,status); androidNotificationManager.notify(prog.hashCode(),notification); if (prog.isFinished()) { finished(prog); } } } @Override public void workStateChanged( WorkEvent ev){ Log.d(TAG,"WorkState changed"); } } ; JobManager.addWorkListener(workListener); Log.d(TAG,"Finished Initializing"); }
Example 56
From project android-api-demos, under directory /src/com/mobeelizer/demos/activities/.
Source file: C2DMReceiver.java

private void handleMessage(final Context context,final Intent intent){ String message=intent.getStringExtra("alert"); String title="Push received!"; if (ApplicationStatus.isVisible()) { final Dialog dialog=new Dialog(ApplicationStatus.getCurrentActivity(),R.style.MobeelizerDialogTheme); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.info_dialog); TextView titleView=(TextView)dialog.findViewById(R.id.dialogTitle); titleView.setText(title); TextView textView=(TextView)dialog.findViewById(R.id.dialogText); textView.setText(message); Button closeButton=(Button)dialog.findViewById(R.id.dialogButton); closeButton.setOnClickListener(new View.OnClickListener(){ public void onClick( final View paramView){ dialog.dismiss(); } } ); dialog.show(); } else { Notification notification=new Notification(R.drawable.ic_launcher,message,System.currentTimeMillis()); notification.setLatestEventInfo(context,title,message,null); notification.flags|=Notification.FLAG_AUTO_CANCEL; NotificationManager notificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(i++,notification); } }
Example 57
From project Android-Battery-Widget, under directory /src/com/em/batterywidget/.
Source file: NotificationsManager.java

@SuppressWarnings("deprecation") public void updateNotificationIcon(Preferences prefSettings,Preferences prefBatteryInfo){ boolean activated=prefSettings.getValue(Constants.NOTIFY_ICON_SETTINGS,false); if (!activated) { if (notificationManager != null) { notificationManager.cancel(_ID); } return; } int status=prefBatteryInfo.getValue(Constants.STATUS,0); int level=prefBatteryInfo.getValue(Constants.LEVEL,0); int plug=prefBatteryInfo.getValue(Constants.PLUG,0); int icon=status == BatteryManager.BATTERY_STATUS_CHARGING ? R.drawable.ic_stat_charge : R.drawable.ic_stat_battery_level; String title=mContext.getString(R.string.app_name); Intent intent=new Intent(mContext,BatteryWidgetActivity.class); PendingIntent pendingIntent=PendingIntent.getActivity(mContext,0,intent,0); RemoteViews contentView=new RemoteViews(mContext.getPackageName(),R.layout.notification); contentView.setImageViewResource(R.id.notificationImage,R.drawable.launcher); contentView.setTextViewText(R.id.notificationTitle,title); contentView.setTextViewText(R.id.notificationStatus,mContext.getString(R.string.textStatus) + getBatteryStatus(status,plug)); Notification notification=new Notification(icon,null,System.currentTimeMillis()); notification.contentView=contentView; notification.contentIntent=pendingIntent; notification.tickerText=null; notification.iconLevel=level; notification.flags=Notification.FLAG_ONGOING_EVENT | Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_NO_CLEAR| Notification.FLAG_SHOW_LIGHTS; notificationManager.notify(_ID,notification); }
Example 58
From project android-tether, under directory /src/og/android/tether/.
Source file: C2DMReceiver.java

public static void generateNotification(Context context,String msg,String title,Intent intent){ int icon=R.drawable.icon_og_bev; long when=System.currentTimeMillis(); Notification notification=new Notification(icon,title,when); notification.setLatestEventInfo(context,title,msg,PendingIntent.getActivity(context,0,intent,0)); notification.flags|=Notification.FLAG_AUTO_CANCEL; notification.defaults=Notification.DEFAULT_ALL; Log.d(TAG,"notification: " + notification.toString()); SharedPreferences settings=prefs(context); int notificatonID=settings.getInt("notificationID",0); NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(notificatonID,notification); playNotificationSound(context); SharedPreferences.Editor editor=settings.edit(); editor.putInt("notificationID",++notificatonID % 32); editor.commit(); }
Example 59
From project androidtracks, under directory /src/org/sfcta/cycletracks/.
Source file: RecordingService.java

public void remindUser(){ soundpool.play(bikebell,1.0f,1.0f,1,0,1.0f); NotificationManager mNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); int icon=R.drawable.icon25; long when=System.currentTimeMillis(); int minutes=(int)(when - trip.startTime) / 60000; CharSequence tickerText=String.format("Still recording (%d min)",minutes); Notification notification=new Notification(icon,tickerText,when); notification.flags|=Notification.FLAG_ONGOING_EVENT | Notification.FLAG_SHOW_LIGHTS; notification.ledARGB=0xffff00ff; notification.ledOnMS=300; notification.ledOffMS=3000; Context context=this; CharSequence contentTitle="CycleTracks - Recording"; CharSequence contentText="Tap to finish your trip"; Intent notificationIntent=new Intent(context,RecordingActivity.class); PendingIntent contentIntent=PendingIntent.getActivity(context,0,notificationIntent,0); notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent); final int RECORDING_ID=1; mNotificationManager.notify(RECORDING_ID,notification); }
Example 60
From project android_7, under directory /src/org/immopoly/android/notification/.
Source file: UserNotification.java

public static void showNotification(Context context,String type,String message,String title){ final int typeOfNotification=Integer.parseInt(type); int icon; switch (typeOfNotification) { case 1: icon=R.drawable.house; break; default : icon=R.drawable.ic_map_button; break; } CharSequence tickerText=message; long when=System.currentTimeMillis(); Context appContext=context.getApplicationContext(); CharSequence contentTitle=title; CharSequence contentText=message; Intent notificationIntent=new Intent(context,ImmopolyActivity.class); notificationIntent.putExtra(ImmopolyActivity.C2DM_START,ImmopolyActivity.START_HISTORY); PendingIntent contentIntent=PendingIntent.getActivity(context,0,notificationIntent,0); Notification notification=new Notification(icon,tickerText,when); notification.setLatestEventInfo(appContext,contentTitle,contentText,contentIntent); notification.flags=Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; String ns=Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager=(NotificationManager)appContext.getSystemService(ns); mNotificationManager.notify(1,notification); }
Example 61
/** * @see com.mexuar.corraleta.protocol.ProtocolEventListener#registered(com.mexuar.corraleta.protocol.Friend,boolean) */ public void registered(Friend f,boolean s){ final Intent intent=new Intent(this,AndroVoIP.class); final PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,0); final NotificationManager notificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); final CharSequence mText=s ? "Registered" : "Unregistered"; final Notification notification=new Notification(R.drawable.icon,getString(R.string.app_name) + " " + mText,System.currentTimeMillis()); notification.setLatestEventInfo(this,getString(R.string.app_name) + " " + mText,f != null ? f.getStatus() : "",pendingIntent); notification.flags|=Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0,notification); this.registered=s; if (s) { this.friend=f; } else if (this.friend != null) { this.friend.stop(); this.friend=null; } }
Example 62
/** * Notify user of the commands Queue size * @return total size of Queues */ private int notifyOfQueue(boolean clearNotification){ int count=mRetryQueue.size() + mCommands.size(); NotificationManager nM=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (count == 0 || clearNotification) { nM.cancel(CommandEnum.NOTIFY_QUEUE.ordinal()); } else if (mNotificationsEnabled) { if (mRetryQueue.size() > 0) { MyLog.d(TAG,mRetryQueue.size() + " commands in Retry Queue."); } if (mCommands.size() > 0) { MyLog.d(TAG,mCommands.size() + " commands in Main Queue."); } Notification notification=new Notification(R.drawable.notification_icon,(String)getText(R.string.notification_title),System.currentTimeMillis()); int messageTitle; String aMessage=""; aMessage=I18n.formatQuantityMessage(getApplicationContext(),R.string.notification_queue_format,count,R.array.notification_queue_patterns,R.array.notification_queue_formats); messageTitle=R.string.notification_title_queue; notification.tickerText=aMessage; PendingIntent pi=PendingIntent.getBroadcast(this,0,new CommandData(CommandEnum.EMPTY,"").toIntent(),0); notification.setLatestEventInfo(this,getText(messageTitle),aMessage,pi); nM.notify(CommandEnum.NOTIFY_QUEUE.ordinal(),notification); } return count; }
Example 63
From project andtweet, under directory /src/com/xorcode/andtweet/.
Source file: AndTweetService.java

/** * Notify user of the commands Queue size * @return total size of Queues */ private int notifyOfQueue(boolean clearNotification){ int count=mRetryQueue.size() + mCommands.size(); NotificationManager nM=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (count == 0 || clearNotification) { nM.cancel(CommandEnum.NOTIFY_QUEUE.ordinal()); } else if (mNotificationsEnabled) { if (mRetryQueue.size() > 0) { d(TAG,mRetryQueue.size() + " commands in Retry Queue."); } if (mCommands.size() > 0) { d(TAG,mCommands.size() + " commands in Main Queue."); } Notification notification=new Notification(R.drawable.notification_icon,(String)getText(R.string.notification_title),System.currentTimeMillis()); int messageTitle; String aMessage=""; aMessage=I18n.formatQuantityMessage(getApplicationContext(),R.string.notification_queue_format,count,R.array.notification_queue_patterns,R.array.notification_queue_formats); messageTitle=R.string.notification_title_queue; notification.tickerText=aMessage; PendingIntent pi=PendingIntent.getBroadcast(this,0,new CommandData(CommandEnum.EMPTY).toIntent(),0); notification.setLatestEventInfo(this,getText(messageTitle),aMessage,pi); nM.notify(CommandEnum.NOTIFY_QUEUE.ordinal(),notification); } return count; }
Example 64
From project apps-for-android, under directory /Photostream/src/com/google/android/photostream/.
Source file: CheckUpdateService.java

@Override public void onProgressUpdate(Object... values){ if (mPreferences.getBoolean(Preferences.KEY_ENABLE_NOTIFICATIONS,true)) { final Integer id=(Integer)values[2]; final Intent intent=new Intent(PhotostreamActivity.ACTION); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(PhotostreamActivity.EXTRA_NOTIFICATION,id); intent.putExtra(PhotostreamActivity.EXTRA_NSID,values[0].toString()); Notification notification=new Notification(R.drawable.stat_notify,getString(R.string.notification_new_photos,values[1]),System.currentTimeMillis()); notification.setLatestEventInfo(CheckUpdateService.this,getString(R.string.notification_title),getString(R.string.notification_contact_has_new_photos,values[1]),PendingIntent.getActivity(CheckUpdateService.this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT)); if (mPreferences.getBoolean(Preferences.KEY_VIBRATE,false)) { notification.defaults|=Notification.DEFAULT_VIBRATE; } String ringtoneUri=mPreferences.getString(Preferences.KEY_RINGTONE,null); notification.sound=TextUtils.isEmpty(ringtoneUri) ? null : Uri.parse(ringtoneUri); mManager.notify(id,notification); } }
Example 65
From project com.juick.android, under directory /src/com/juick/android/.
Source file: CheckUpdatesReceiver.java

@Override public void onReceive(Context context,Intent intent){ final String jsonStr=Utils.getJSON(context,"http://api.juick.com/notifications"); if (jsonStr != null && jsonStr.length() > 4) { try { JSONObject json=new JSONObject(jsonStr); int messages=json.getInt("messages"); String str="New messages: " + messages; Intent i=new Intent(context,MainActivity.class); PendingIntent contentIntent=PendingIntent.getActivity(context,0,i,PendingIntent.FLAG_UPDATE_CURRENT); Notification notification=new Notification(R.drawable.ic_notification,str,System.currentTimeMillis()); notification.setLatestEventInfo(context.getApplicationContext(),str,str,contentIntent); notification.flags|=Notification.FLAG_AUTO_CANCEL; notification.defaults|=Notification.DEFAULT_LIGHTS; ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(1,notification); } catch ( JSONException e) { Log.e("CheckUpdatesReceiver",e.toString()); } } }
Example 66
From project cw-omnibus, under directory /Notifications/HCNotifyDemo/src/com/commonsware/android/hcnotify/.
Source file: SillyService.java

@Override protected void onHandleIntent(Intent intent){ NotificationManager mgr=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder builder=new NotificationCompat.Builder(this); builder.setContent(buildContent(0)).setTicker(getText(R.string.ticker),buildTicker()).setContentIntent(buildContentIntent()).setLargeIcon(buildLargeIcon()).setSmallIcon(R.drawable.ic_stat_notif_small_icon).setOngoing(true); Notification notif=builder.build(); for (int i=0; i < 20; i++) { notif.contentView.setProgressBar(android.R.id.progress,100,i * 5,false); mgr.notify(NOTIFICATION_ID,notif); if (i == 0) { notif.tickerText=null; notif.tickerView=null; } SystemClock.sleep(1000); } mgr.cancel(NOTIFICATION_ID); }
Example 67
From project DeliciousDroid, under directory /src/com/deliciousdroid/action/.
Source file: AddBookmarkTask.java

private void throwError(){ NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Random r=new Random(); int notification=r.nextInt(); Notification n=new Notification(R.drawable.ic_main,"DeliciousDroid Error",System.currentTimeMillis()); Intent ni=new Intent(context,AddBookmark.class); ni.setAction(Intent.ACTION_SEND); ni.setData(Uri.parse("content://com.deliciousdroid.bookmarks/" + Integer.toString(notification))); ni.putExtra(Intent.EXTRA_TEXT,bookmark.getUrl()); ni.putExtra(Constants.EXTRA_DESCRIPTION,bookmark.getDescription()); ni.putExtra(Constants.EXTRA_NOTES,bookmark.getNotes()); ni.putExtra(Constants.EXTRA_TAGS,bookmark.getTagString()); ni.putExtra(Constants.EXTRA_PRIVATE,bookmark.getPrivate()); ni.putExtra(Constants.EXTRA_ERROR,true); if (update) { ni.putExtra(Intent.EXTRA_TEXT + ".old",oldBookmark.getUrl()); ni.putExtra(Constants.EXTRA_DESCRIPTION + ".old",oldBookmark.getDescription()); ni.putExtra(Constants.EXTRA_NOTES + ".old",oldBookmark.getNotes()); ni.putExtra(Constants.EXTRA_TAGS + ".old",oldBookmark.getTagString()); ni.putExtra(Constants.EXTRA_PRIVATE + ".old",oldBookmark.getPrivate()); ni.putExtra(Constants.EXTRA_TIME + ".old",oldBookmark.getTime()); } ni.putExtra(Constants.EXTRA_UPDATE,update); ni.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); n.flags|=Notification.FLAG_AUTO_CANCEL; n.flags|=Notification.FLAG_NO_CLEAR; PendingIntent ci=PendingIntent.getActivity(context,0,ni,PendingIntent.FLAG_UPDATE_CURRENT); n.setLatestEventInfo(context,"DeliciousDroid Error","Error Saving Bookmark",ci); nm.notify(notification,n); }
Example 68
From project dmix, under directory /MPDroid/src/com/namelessdev/mpdroid/.
Source file: StreamingService.java

@Override public void onDestroy(){ if (needStoppedNotification) { ((NotificationManager)getSystemService(NOTIFICATION_SERVICE)).cancel(STREAMINGSERVICE_PAUSED); Notification status=new NotificationCompat.Builder(this).setContentTitle(getString(R.string.streamStopped)).setSmallIcon(R.drawable.icon).setContentIntent(PendingIntent.getActivity(this,0,new Intent("com.namelessdev.mpdroid.PLAYBACK_VIEWER").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),0)).getNotification(); ((NotificationManager)getSystemService(NOTIFICATION_SERVICE)).notify(STREAMINGSERVICE_STOPPED,status); } isServiceRunning=false; setMusicState(PLAYSTATE_STOPPED); unregisterMediaButtonEvent(); unregisterRemoteControlClient(); audioManager.abandonAudioFocus(this); if (mediaPlayer != null) { mediaPlayer.stop(); mediaPlayer.release(); mediaPlayer=null; } MPDApplication app=(MPDApplication)getApplication(); app.unsetActivity(this); app.getApplicationState().streamingMode=false; super.onDestroy(); }
Example 69
From project DownloadProvider, under directory /src/com/mozillaonline/providers/downloads/.
Source file: DownloadNotification.java

private void updateCompletedNotification(Collection<DownloadInfo> downloads){ for ( DownloadInfo download : downloads) { if (!isCompleteAndVisible(download)) { continue; } Notification n=new Notification(); n.icon=android.R.drawable.stat_sys_download_done; long id=download.mId; String title=download.mTitle; if (title == null || title.length() == 0) { title=mContext.getResources().getString(R.string.download_unknown_title); } Uri contentUri=ContentUris.withAppendedId(Downloads.ALL_DOWNLOADS_CONTENT_URI,id); String caption; Intent intent; if (Downloads.isStatusError(download.mStatus)) { caption=mContext.getResources().getString(R.string.notification_download_failed); intent=new Intent(Constants.ACTION_LIST); } else { caption=mContext.getResources().getString(R.string.notification_download_complete); if (download.mDestination == Downloads.DESTINATION_EXTERNAL) { intent=new Intent(Constants.ACTION_OPEN); } else { intent=new Intent(Constants.ACTION_LIST); } } intent.setClassName(mContext.getPackageName(),DownloadReceiver.class.getName()); intent.setData(contentUri); n.when=download.mLastMod; n.setLatestEventInfo(mContext,title,caption,PendingIntent.getBroadcast(mContext,0,intent,0)); intent=new Intent(Constants.ACTION_HIDE); intent.setClassName(mContext.getPackageName(),DownloadReceiver.class.getName()); intent.setData(contentUri); n.deleteIntent=PendingIntent.getBroadcast(mContext,0,intent,0); mSystemFacade.postNotification(download.mId,n); } }
Example 70
From project Dual-Battery-Widget, under directory /src/org/flexlabs/widgets/dualbattery/service/.
Source file: NotificationManager.java

public void update(int dockLevel,boolean charging){ if (!enabled) { return; } int icon=charging ? R.drawable.stat_sys_battery_charge : R.drawable.stat_sys_battery; Notification notification=new Notification(icon,null,System.currentTimeMillis()); notification.iconLevel=dockLevel; notification.flags=Notification.FLAG_ONGOING_EVENT | Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_NO_CLEAR; Intent intent=new Intent(mContext,BatteryHistoryActivity.class); PendingIntent contentIntent=PendingIntent.getActivity(mContext,1,intent,0); notification.setLatestEventInfo(mContext,title,"Dock battery level: " + dockLevel + "%",contentIntent); notification.tickerText=null; notification.contentView.setInt(android.R.id.icon,"setImageLevel",dockLevel); mNotificationManager.notify(NOTIFICATION_DOCK,notification); }
Example 71
From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/model/.
Source file: PresenceAwareNotify.java

public void notify(String notificationTitle,String notificationMsg,String notificationSubMsg,PendingIntent contentIntent){ boolean doAlert=true; if (mContext.getSharedPreferences("main",0).getBoolean("autoplay",false)) { return; } if (Push2TalkPresence.getInstance().isOnCall()) { doAlert=false; } if (MusubiBaseActivity.getInstance().amResumed()) { doAlert=false; } Notification notification=new Notification(R.drawable.icon,notificationTitle,System.currentTimeMillis()); notification.setLatestEventInfo(mContext,notificationMsg,notificationSubMsg,contentIntent); notification.flags=Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; if (doAlert) { SharedPreferences settings=mContext.getSharedPreferences(PREFS_NAME,0); String uri=settings.getString("ringtone",null); notification.vibrate=VIBRATE; if (!uri.equals("none")) { notification.sound=Uri.parse(uri); } } mNotificationManager.notify(NOTIFY_ID,notification); }
Example 72
From project eclipse-ui-tips, under directory /EclipseUITips/src/name/raev/kaloyan/android/eclipseuitips/.
Source file: AlarmReceiver.java

@Override public void onReceive(Context context,Intent intent){ String ns=Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager=(NotificationManager)context.getSystemService(ns); Notification notification=new Notification(R.drawable.ic_stat_notify_eclipse,context.getString(R.string.notify_ticker_text),0); notification.flags=Notification.FLAG_AUTO_CANCEL; Guideline guideline=Guideline.random(); Intent notificationIntent=new Intent(context,GuidelinesPagerActivity.class); notificationIntent.putExtra(Guideline.EXTRA_INDEX,guideline.ordinal()); notificationIntent.putExtra(Guideline.EXTRA_HIGHLIGHTED,true); PendingIntent contentIntent=PendingIntent.getActivity(context,0,notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT); CharSequence contentTitle=context.getString(guideline.subcategory().title()); CharSequence contentText=context.getString(guideline.text()); notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent); mNotificationManager.notify(1,notification); }
Example 73
From project ElectricSleep, under directory /src/com/androsz/electricsleepbeta/alarmclock/.
Source file: AlarmAlertFullScreen.java

private void snooze(){ if (!findViewById(R.id.snooze).isEnabled()) { dismiss(false); return; } new AsyncTask<Void,Void,Integer>(){ final Calendar c=Calendar.getInstance(); @Override protected Integer doInBackground( Void... params){ final String snooze=getSharedPreferences(SettingsActivity.PREFERENCES,0).getString(SettingsActivity.KEY_ALARM_SNOOZE,DEFAULT_SNOOZE); final int snoozeMinutes=Integer.parseInt(snooze); final long snoozeTime=System.currentTimeMillis() + 1000 * 60 * snoozeMinutes; Alarms.saveSnoozeAlert(AlarmAlertFullScreen.this,mAlarm.id,snoozeTime); c.setTimeInMillis(snoozeTime); return snoozeMinutes; } @Override protected void onPostExecute( Integer snoozeMinutes){ String label=mAlarm.getLabelOrDefault(AlarmAlertFullScreen.this); label=getString(R.string.alarm_notify_snooze_label,label); final Intent cancelSnooze=new Intent(AlarmAlertFullScreen.this,AlarmReceiver.class); cancelSnooze.setAction(Alarms.CANCEL_SNOOZE); cancelSnooze.putExtra(Alarms.ALARM_ID,mAlarm.id); final PendingIntent broadcast=PendingIntent.getBroadcast(AlarmAlertFullScreen.this,mAlarm.id,cancelSnooze,0); final NotificationManager nm=getNotificationManager(); final Notification n=new Notification(R.drawable.ic_alarm_neutral,label,0); n.setLatestEventInfo(AlarmAlertFullScreen.this,label,getString(R.string.alarm_notify_snooze_text,Alarms.formatTime(AlarmAlertFullScreen.this,c)),broadcast); n.flags|=Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONGOING_EVENT; nm.notify(mAlarm.id,n); final String displayTime=getString(R.string.alarm_alert_snooze_set,snoozeMinutes); Log.v(displayTime); Toast.makeText(AlarmAlertFullScreen.this,displayTime,Toast.LENGTH_LONG).show(); stopService(new Intent(Alarms.ALARM_ALERT_ACTION)); finish(); } } .execute(); }
Example 74
From project fanfoudroid, under directory /src/com/ch_linghu/fanfoudroid/service/.
Source file: TwitterService.java

private void notify(PendingIntent intent,int notificationId,int notifyIconId,String tickerText,String title,String text){ Notification notification=new Notification(notifyIconId,tickerText,System.currentTimeMillis()); notification.setLatestEventInfo(this,title,text,intent); notification.flags=Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_SHOW_LIGHTS; notification.ledARGB=0xFF84E4FA; notification.ledOnMS=5000; notification.ledOffMS=5000; String ringtoneUri=TwitterApplication.mPref.getString(Preferences.RINGTONE_KEY,null); if (ringtoneUri == null) { notification.defaults|=Notification.DEFAULT_SOUND; } else { notification.sound=Uri.parse(ringtoneUri); } if (TwitterApplication.mPref.getBoolean(Preferences.VIBRATE_KEY,false)) { notification.defaults|=Notification.DEFAULT_VIBRATE; } mNotificationManager.notify(notificationId,notification); }
Example 75
From project gmarks-android, under directory /src/main/java/org/thomnichols/android/gmarks/.
Source file: RemoteSyncTask.java

RemoteSyncTask(Context ctx){ this.ctx=ctx; notificationManager=(NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE); notification=new Notification(R.drawable.ic_sync,ctx.getString(R.string.sync_notify_start),System.currentTimeMillis()); this.syncPrefs=Prefs.get(this.ctx); this.legacySyncPrefs=ctx.getSharedPreferences(SHARED_PREFS_NAME,Context.MODE_PRIVATE); }
Example 76
From project GSM-Signal-Tracking-, under directory /gpstracker/src/nl/sogeti/android/gpstracker/actions/.
Source file: 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(ContentUris.withAppendedId(Tracks.CONTENT_URI,mTrackId)); 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); }
Example 77
From project HarleyDroid, under directory /src/org/harleydroid/.
Source file: HarleyDroidService.java

@Override public void onCreate(){ super.onCreate(); if (D) Log.d(TAG,"onCreate()"); mHD=new HarleyData(); J1850.resetCounters(); mNM=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); notification=new Notification(R.drawable.ic_stat_notify_harleydroid,"",System.currentTimeMillis()); notification.flags=Notification.FLAG_ONGOING_EVENT; notificationIntent=PendingIntent.getActivity(this,0,new Intent(this,HarleyDroidDashboard.class),0); notify(R.string.notification_connecting); }
Example 78
From project iohack, under directory /src/org/alljoyn/bus/sample/chat/.
Source file: AllJoynService.java

/** * Our onCreate() method is called by the Android appliation framework when the service is first created. We spin up a background thread to handle any long-lived requests (pretty much all AllJoyn calls that involve communication with remote processes) that need to be done and insinuate ourselves into the list of observers of the model so we can get event notifications. */ public void onCreate(){ Log.i(TAG,"onCreate()"); startBusThread(); mChatApplication=(ChatApplication)getApplication(); mChatApplication.addObserver(this); CharSequence title="AllJoyn"; CharSequence message="Chat Channel Hosting Service."; Intent intent=new Intent(this,TabWidget.class); PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,0); Notification notification=new Notification(R.drawable.icon,null,System.currentTimeMillis()); notification.setLatestEventInfo(this,title,message,pendingIntent); notification.flags|=Notification.DEFAULT_SOUND | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; Log.i(TAG,"onCreate(): startForeground()"); startForeground(NOTIFICATION_ID,notification); mBackgroundHandler.connect(); mBackgroundHandler.startDiscovery(); }
Example 79
From project k-9, under directory /src/com/fsck/k9/helper/.
Source file: NotificationBuilderApi1.java

@SuppressWarnings("deprecation") @Override public Notification getNotification(){ Notification notification=new Notification(mSmallIcon,mTickerText,mWhen); notification.number=mNumber; notification.setLatestEventInfo(mContext,mContentTitle,mContentText,mContentIntent); if (mSoundUri != null) { notification.sound=mSoundUri; notification.audioStreamType=AudioManager.STREAM_NOTIFICATION; } if (mVibrationPattern != null) { notification.vibrate=mVibrationPattern; } if (mBlinkLed) { notification.flags|=Notification.FLAG_SHOW_LIGHTS; notification.ledARGB=mLedColor; notification.ledOnMS=mLedOnMS; notification.ledOffMS=mLedOffMS; } if (mAutoCancel) { notification.flags|=Notification.FLAG_AUTO_CANCEL; } if (mOngoing) { notification.flags|=Notification.FLAG_ONGOING_EVENT; } return notification; }
Example 80
From project LDAP-Sync, under directory /src/de/danielweisser/android/ldapsync/client/.
Source file: LDAPUtilities.java

/** * Obtains a list of all contacts from the LDAP Server. * @param ldapServer The LDAP server data * @param baseDN The baseDN that will be used for the search * @param searchFilter The search filter * @param mappingBundle A bundle of all LDAP attributes that are queried * @param mLastUpdated Date of the last update * @param context The caller Activity's context * @return List of all LDAP contacts */ public static List<Contact> fetchContacts(final LDAPServerInstance ldapServer,final String baseDN,final String searchFilter,final Bundle mappingBundle,final Date mLastUpdated,final Context context){ final ArrayList<Contact> friendList=new ArrayList<Contact>(); LDAPConnection connection=null; try { connection=ldapServer.getConnection(); SearchResult searchResult=connection.search(baseDN,SearchScope.SUB,searchFilter,getUsedAttributes(mappingBundle)); Log.i(TAG,searchResult.getEntryCount() + " entries returned."); for ( SearchResultEntry e : searchResult.getSearchEntries()) { Contact u=Contact.valueOf(e,mappingBundle); if (u != null) { friendList.add(u); } } } catch ( LDAPException e) { Log.v(TAG,"LDAPException on fetching contacts",e); NotificationManager mNotificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); int icon=R.drawable.icon; CharSequence tickerText="Error on LDAP Sync"; Notification notification=new Notification(icon,tickerText,System.currentTimeMillis()); Intent notificationIntent=new Intent(context,SyncService.class); PendingIntent contentIntent=PendingIntent.getService(context,0,notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT); notification.setLatestEventInfo(context,tickerText,e.getMessage().replace("\\n"," "),contentIntent); notification.flags=Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(0,notification); return null; } finally { if (connection != null) { connection.close(); } } return friendList; }
Example 81
From project Locast-Android, under directory /src/edu/mit/mobile/android/locast/notifications/.
Source file: ProgressNotification.java

/** * Mark the progress done. This should be called even if the transfer is unsuccessful. If you set leaveWhenDone, then make sure that you have set any doneTitle, doneText, and doneIntent that you want set. * @param id an ID that's unique for the set of things being done. */ public void done(int id){ if (mLeaveWhenDone) { int doneIcon; if (successful) { doneIcon=this.doneIcon != 0 ? this.doneIcon : icon; } else { doneIcon=android.R.drawable.stat_notify_error; } final Notification doneNotification=new Notification(doneIcon,doneTitle,System.currentTimeMillis()); doneNotification.flags|=Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL; doneNotification.setLatestEventInfo(mContext,doneTitle,doneText,doneIntent); nm.notify(NOTIFICATION_BASE + id,doneNotification); } }
Example 82
From project lullaby, under directory /src/net/sileht/lullaby/player/.
Source file: PlayerService.java

private void setState(STATE state){ boolean isPreviouslyPlaying=isPlaying(); STATE pm=mState; mState=state; boolean isPlaying=isPlaying(); Log.d(TAG,"ps:" + isPreviouslyPlaying + " - pm:"+ pm+ " | s:"+ isPlaying+ " - "+ mState); if (isPlaying != isPreviouslyPlaying) { for ( OnStatusListener obj : mPlayerListeners) { obj.onTogglePlaying(isPlaying); } if (isPlaying) { if (mSong != null) { RemoteViews views=new RemoteViews(this.getPackageName(),R.layout.statusbar); views.setImageViewResource(R.id.icon,R.drawable.status_icon); views.setTextViewText(R.id.trackname,mSong.name); views.setTextViewText(R.id.artistalbum,mSong.album + " - " + mSong.artist); Notification n=new Notification(); n.icon=R.drawable.status_icon; n.tickerText=getString(R.string.playing) + " " + mSong.name; n.flags|=Notification.FLAG_ONGOING_EVENT; n.contentView=views; Intent i=new Intent(this,PlayingActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); n.contentIntent=PendingIntent.getActivity(this,0,i,0); startForeground(1,n); } } else { stopForeground(true); } } Log.d(TAG,"setState(" + mState + ")"); }
Example 83
From project milton, under directory /milton/apps/milton-android-photouploader/src/com/ettrema/android/photouploader/.
Source file: ApplicationNotification.java

/** * Enable application notification * @param application Main application instance */ public void enable(Context context){ if (isEnabled) { return; } try { manager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification=new Notification(R.drawable.uploader,null,System.currentTimeMillis()); notification.flags|=Notification.FLAG_ONGOING_EVENT; Intent notificationIntent=new Intent(context,MiltonPhotoUploader.class); PendingIntent contentIntent=PendingIntent.getActivity(context,0,notificationIntent,0); notification.setLatestEventInfo(context,context.getString(R.string.app_name),context.getString(R.string.app_name) + " is running.",contentIntent); manager.notify(APP_NOTIFICAION,notification); isEnabled=true; } catch ( Exception e) { } }
Example 84
From project milton2, under directory /apps/milton-android-photouploader/src/com/ettrema/android/photouploader/.
Source file: ApplicationNotification.java

/** * Enable application notification * @param application Main application instance */ public void enable(Context context){ if (isEnabled) { return; } try { manager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification=new Notification(R.drawable.uploader,null,System.currentTimeMillis()); notification.flags|=Notification.FLAG_ONGOING_EVENT; Intent notificationIntent=new Intent(context,MiltonPhotoUploader.class); PendingIntent contentIntent=PendingIntent.getActivity(context,0,notificationIntent,0); notification.setLatestEventInfo(context,context.getString(R.string.app_name),context.getString(R.string.app_name) + " is running.",contentIntent); manager.notify(APP_NOTIFICAION,notification); isEnabled=true; } catch ( Exception e) { } }
Example 85
From project android-voip-service, under directory /src/main/java/org/linphone/.
Source file: LinphoneService.java

@Override public void onCreate(){ super.onCreate(); instance=this; LinphonePreferenceManager.getInstance(this); PreferenceManager.setDefaultValues(this,R.xml.linphone_preferences,true); notificationTitle=getString(R.string.app_name); Hacks.dumpDeviceInformation(); dumpInstalledLinphoneInformation(); mNotificationMgr=(NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE); mNotif=new Notification(R.drawable.status_level,"",System.currentTimeMillis()); mNotif.iconLevel=IC_LEVEL_ORANGE; mNotif.flags|=Notification.FLAG_ONGOING_EVENT; Intent notifIntent=new Intent(this,LinphoneActivity.class); mNotifContentIntent=PendingIntent.getActivity(this,0,notifIntent,0); mNotif.setLatestEventInfo(this,notificationTitle,"",mNotifContentIntent); mNotificationMgr.notify(NOTIF_ID,mNotif); LinphoneManager.createAndStart(this,this); }
Example 86
From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/bluetooth/.
Source file: DockService.java

private boolean createDialog(DockService service,BluetoothDevice device,int state,int startId){ switch (state) { case Intent.EXTRA_DOCK_STATE_CAR: case Intent.EXTRA_DOCK_STATE_DESK: break; default : return false; } startForeground(0,new Notification()); boolean firstTime=!mBtManager.hasDockAutoConnectSetting(device.getAddress()); CharSequence[] items=initBtSettings(service,device,state,firstTime); final AlertDialog.Builder ab=new AlertDialog.Builder(service); ab.setTitle(service.getString(R.string.bluetooth_dock_settings_title)); ab.setMultiChoiceItems(items,mCheckedItems,service); LayoutInflater inflater=(LayoutInflater)service.getSystemService(Context.LAYOUT_INFLATER_SERVICE); float pixelScaleFactor=service.getResources().getDisplayMetrics().density; View view=inflater.inflate(R.layout.remember_dock_setting,null); CheckBox rememberCheckbox=(CheckBox)view.findViewById(R.id.remember); boolean checked=firstTime || mBtManager.getDockAutoConnectSetting(device.getAddress()); rememberCheckbox.setChecked(checked); rememberCheckbox.setOnCheckedChangeListener(this); int viewSpacingLeft=(int)(14 * pixelScaleFactor); int viewSpacingRight=(int)(14 * pixelScaleFactor); ab.setView(view,viewSpacingLeft,0,viewSpacingRight,0); if (DEBUG) { Log.d(TAG,"Auto connect = " + mBtManager.getDockAutoConnectSetting(device.getAddress())); } ab.setPositiveButton(service.getString(android.R.string.ok),service); mStartIdAssociatedWithDialog=startId; mDialog=ab.create(); mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); mDialog.setOnDismissListener(service); mDialog.show(); return true; }
Example 87
From project andlytics, under directory /src/com/github/andlyticsproject/io/.
Source file: ExportService.java

private void notifyExportFinished(boolean success){ notificationManager.cancel(NOTIFICATION_ID_PROGRESS); Intent shareIntent=createShareIntent(); PendingIntent pendingIntent=PendingIntent.getActivity(getApplicationContext(),0,shareIntent,PendingIntent.FLAG_UPDATE_CURRENT); String message=getApplicationContext().getString(R.string.export_saved_to) + ": " + StatsCsvReaderWriter.getExportDirPath(); String title=getResources().getString(R.string.app_name) + ": " + getApplicationContext().getString(R.string.export_finished); Builder builder=new NotificationCompat2.Builder(getApplicationContext()); builder.setSmallIcon(R.drawable.statusbar_andlytics); builder.setContentTitle(title); builder.setContentText(message); BigTextStyle style=new BigTextStyle(builder); style.bigText(message); style.setBigContentTitle(title); style.setSummaryText(accountName); builder.setStyle(style); builder.setContentIntent(pendingIntent); builder.setWhen(System.currentTimeMillis()); builder.setDefaults(Notification.DEFAULT_ALL); builder.setAutoCancel(true); builder.setOngoing(false); notificationManager.notify(NOTIFICATION_ID_FINISHED,builder.build()); }
Example 88
From project android_packages_apps_CellBroadcastReceiver, under directory /src/com/android/cellbroadcastreceiver/.
Source file: CellBroadcastAlertService.java

/** * Display a full-screen alert message for emergency alerts. * @param message the alert to display */ private void openEmergencyAlertNotification(CellBroadcastMessage message){ acquireTimedWakelock(WAKE_LOCK_TIMEOUT); Intent closeDialogs=new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); sendBroadcast(closeDialogs); Intent audioIntent=new Intent(this,CellBroadcastAlertAudio.class); audioIntent.setAction(CellBroadcastAlertAudio.ACTION_START_ALERT_AUDIO); SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this); String duration=prefs.getString(CellBroadcastSettings.KEY_ALERT_SOUND_DURATION,CellBroadcastSettings.ALERT_SOUND_DEFAULT_DURATION); audioIntent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_DURATION_EXTRA,Integer.parseInt(duration)); int channelTitleId=CellBroadcastResources.getDialogTitleResource(message); CharSequence channelName=getText(channelTitleId); String messageBody=message.getMessageBody(); if (prefs.getBoolean(CellBroadcastSettings.KEY_ENABLE_ALERT_SPEECH,true)) { audioIntent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_MESSAGE_BODY,messageBody); String language=message.getLanguageCode(); if (message.isEtwsMessage() && !"ja".equals(language)) { Log.w(TAG,"bad language code for ETWS - using Japanese TTS"); language="ja"; } else if (message.isCmasMessage() && !"en".equals(language)) { Log.w(TAG,"bad language code for CMAS - using English TTS"); language="en"; } audioIntent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_MESSAGE_LANGUAGE,language); } startService(audioIntent); int notificationId=(int)message.getDeliveryTime(); Class c=CellBroadcastAlertDialog.class; KeyguardManager km=(KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE); if (km.inKeyguardRestrictedInputMode()) { c=CellBroadcastAlertFullScreen.class; } Intent notify=createDisplayMessageIntent(this,c,message,notificationId); PendingIntent pi=PendingIntent.getActivity(this,notificationId,notify,0); Notification.Builder builder=new Notification.Builder(this).setSmallIcon(R.drawable.ic_notify_alert).setTicker(getText(CellBroadcastResources.getDialogTitleResource(message))).setWhen(System.currentTimeMillis()).setContentIntent(pi).setFullScreenIntent(pi,true).setContentTitle(channelName).setContentText(messageBody).setDefaults(Notification.DEFAULT_LIGHTS); NotificationManager notificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId,builder.getNotification()); }
Example 89
From project android_packages_apps_Nfc, under directory /src/com/android/nfc/handover/.
Source file: HandoverManager.java

synchronized void updateNotification(){ if (!incoming) return; Builder notBuilder=new Notification.Builder(mContext); if (state == STATE_NEW || state == STATE_IN_PROGRESS || state == STATE_W4_NEXT_TRANSFER || state == STATE_W4_MEDIA_SCANNER) { notBuilder.setAutoCancel(false); notBuilder.setSmallIcon(android.R.drawable.stat_sys_download); notBuilder.setTicker(mContext.getString(R.string.beam_progress)); notBuilder.setContentTitle(mContext.getString(R.string.beam_progress)); notBuilder.addAction(R.drawable.ic_menu_cancel_holo_dark,mContext.getString(R.string.cancel),cancelIntent); notBuilder.setDeleteIntent(cancelIntent); notBuilder.setProgress(100,0,true); } else if (state == STATE_SUCCESS) { notBuilder.setAutoCancel(true); notBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done); notBuilder.setTicker(mContext.getString(R.string.beam_complete)); notBuilder.setContentTitle(mContext.getString(R.string.beam_complete)); notBuilder.setContentText(mContext.getString(R.string.beam_touch_to_view)); Intent viewIntent=buildViewIntent(); PendingIntent contentIntent=PendingIntent.getActivity(mContext,0,viewIntent,0); notBuilder.setContentIntent(contentIntent); NfcService.getInstance().playSound(NfcService.SOUND_END); } else if (state == STATE_FAILED) { notBuilder.setAutoCancel(false); notBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done); notBuilder.setTicker(mContext.getString(R.string.beam_failed)); notBuilder.setContentTitle(mContext.getString(R.string.beam_failed)); } else if (state == STATE_CANCELLED) { notBuilder.setAutoCancel(false); notBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done); notBuilder.setTicker(mContext.getString(R.string.beam_canceled)); notBuilder.setContentTitle(mContext.getString(R.string.beam_canceled)); } else { return; } mNotificationManager.notify(mNotificationId,notBuilder.build()); }
Example 90
From project creamed_glacier_app_settings, under directory /src/com/android/settings/bluetooth/.
Source file: BluetoothPairingRequest.java

@Override public void onReceive(Context context,Intent intent){ String action=intent.getAction(); if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) { BluetoothDevice device=intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); int type=intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,BluetoothDevice.ERROR); Intent pairingIntent=new Intent(); pairingIntent.setClass(context,BluetoothPairingDialog.class); pairingIntent.putExtra(BluetoothDevice.EXTRA_DEVICE,device); pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,type); if (type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION || type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY || type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) { int pairingKey=intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,BluetoothDevice.ERROR); pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY,pairingKey); } pairingIntent.setAction(BluetoothDevice.ACTION_PAIRING_REQUEST); pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PowerManager powerManager=(PowerManager)context.getSystemService(Context.POWER_SERVICE); String deviceAddress=device != null ? device.getAddress() : null; if (powerManager.isScreenOn() && LocalBluetoothPreferences.shouldShowDialogInForeground(context,deviceAddress)) { context.startActivity(pairingIntent); } else { Resources res=context.getResources(); Notification.Builder builder=new Notification.Builder(context).setSmallIcon(android.R.drawable.stat_sys_data_bluetooth).setTicker(res.getString(R.string.bluetooth_notif_ticker)); PendingIntent pending=PendingIntent.getActivity(context,0,pairingIntent,PendingIntent.FLAG_ONE_SHOT); String name=intent.getStringExtra(BluetoothDevice.EXTRA_NAME); if (TextUtils.isEmpty(name)) { name=device != null ? device.getAliasName() : context.getString(android.R.string.unknownName); } builder.setContentTitle(res.getString(R.string.bluetooth_notif_title)).setContentText(res.getString(R.string.bluetooth_notif_message,name)).setContentIntent(pending).setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND); NotificationManager manager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(NOTIFICATION_ID,builder.getNotification()); } } else if (action.equals(BluetoothDevice.ACTION_PAIRING_CANCEL)) { NotificationManager manager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); manager.cancel(NOTIFICATION_ID); } }
Example 91
From project empub, under directory /src/com/commonsware/empub/.
Source file: DownloadCompleteReceiver.java

@TargetApi(11) @Override public void onReceive(final Context ctxt,Intent unused){ File update=new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),DownloadCheckTask.UPDATE_FILENAME); if (update.exists()) { Intent i; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { i=new Intent(Intent.ACTION_INSTALL_PACKAGE); i.putExtra(Intent.EXTRA_ALLOW_REPLACE,true); } else { i=new Intent(Intent.ACTION_VIEW); } i.setDataAndType(Uri.fromFile(update),"application/vnd.android.package-archive"); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); NotificationCompat.Builder b=new NotificationCompat.Builder(ctxt); b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis()); b.setContentTitle(ctxt.getString(R.string.empub_download_complete)).setContentText(ctxt.getString(R.string.empub_download_install)).setSmallIcon(android.R.drawable.stat_sys_download_done).setTicker(ctxt.getString(R.string.empub_download_complete)); b.setContentIntent(PendingIntent.getActivity(ctxt,0,i,0)); NotificationManager mgr=(NotificationManager)ctxt.getSystemService(Context.NOTIFICATION_SERVICE); mgr.notify(NOTIFY_ID,b.getNotification()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final PendingResult pr=goAsync(); new Thread(){ public void run(){ makeMeGoByeBye(ctxt); pr.finish(); } } .start(); } else { makeMeGoByeBye(ctxt); } } }
Example 92
@Override protected void onPostExecute(Boolean result){ if (result && !mediaError) { b2evolution.postUploaded(); nm.cancel(notificationID); } else { if (mediaError) b2evolution.postUploaded(); String postOrPage=(String)(post.isPage() ? context.getResources().getText(R.string.page_id) : context.getResources().getText(R.string.post_id)); Intent notificationIntent=new Intent(context,Posts.class); notificationIntent.setData((Uri.parse("custom://b2evolutionNotificationIntent" + post.blogID))); notificationIntent.putExtra("fromNotification",true); notificationIntent.putExtra("errorMessage",error); PendingIntent pendingIntent=PendingIntent.getActivity(context,0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT); n.flags|=Notification.FLAG_AUTO_CANCEL; String errorText=context.getResources().getText(R.string.upload_failed).toString(); if (mediaError) errorText=context.getResources().getText(R.string.media) + " " + context.getResources().getText(R.string.error); n.setLatestEventInfo(context,(mediaError) ? errorText : context.getResources().getText(R.string.upload_failed),postOrPage + " " + errorText+ ": "+ error,pendingIntent); nm.notify(notificationID,n); } }
Example 93
From project Juggernaut_SystemUI, under directory /src/com/android/systemui/statusbar/.
Source file: NotificationData.java

/** * Return whether there are any clearable items (that aren't errors). */ public boolean hasClearableItems(){ final int N=mEntries.size(); for (int i=0; i < N; i++) { Entry entry=mEntries.get(i); if (entry.expanded != null) { if ((entry.notification.notification.flags & Notification.FLAG_NO_CLEAR) == 0) { return true; } } } return false; }