List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:com.bangz.smartmute.services.LocationMuteService.java
private void NotificationUserFailed() { NotificationCompat.Builder nb = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_notification) .setColor(getResources().getColor(R.color.theme_accent_2)) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setAutoCancel(true); // LocationManager lm = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE); // boolean bProviderEnabled = // lm.isProviderEnabled(LocationManager.GPS_PROVIDER) | // lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); int locationmode = ApiAdapterFactory.getApiAdapter().getLocationMode(this); if (locationmode <= ApiAdapter.LOCATION_MODE_SENSORS_ONLY) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); nb.setContentTitle(getResources().getString(R.string.location_provider_disabled_title)); nb.setContentText(getResources().getString(R.string.location_provider_disabled_text)); nb.setContentIntent(pi);//from w ww. j a va2 s. c o m } else { // GPS and Network location provider is OK. let use try again Intent intent = new Intent(ACTION_START_GEOFENCES, null, this, LocationMuteService.class); PendingIntent pi = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); nb.setContentTitle(getResources().getString(R.string.geo_not_available_retry_title)); nb.setContentText(getResources().getString(R.string.geo_not_available_retry_text)); nb.setContentIntent(pi); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(GEOFENCE_NOT_AVLIABLE_NOTIFICATION_ID, nb.build()); }
From source file:MainActivity.java
public void clickLightsActionSound(View view) { NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("LightsActionSoundRedux") .setContentText("Lights, Action & Sound").setSound(notificationSoundUri) .setLights(Color.BLUE, 500, 500).setVibrate(new long[] { 250, 500, 250, 500, 250, 500 }); notificationManager.notify(0, notificationBuilder.build()); }
From source file:com.androzic.plugin.tracker.SMSReceiver.java
@Override public void onReceive(Context context, Intent intent) { String Sender = ""; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Log.e(TAG, "SMS received"); Bundle extras = intent.getExtras();/*from w ww . jav a2 s . co m*/ if (extras == null) return; StringBuilder messageBuilder = new StringBuilder(); Object[] pdus = (Object[]) extras.get("pdus"); for (int i = 0; i < pdus.length; i++) { SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]); String text = msg.getMessageBody(); Sender = msg.getDisplayOriginatingAddress(); Log.w(TAG, "Sender: " + Sender); if (text == null) continue; messageBuilder.append(text); } String text = messageBuilder.toString(); boolean flexMode = prefs.getBoolean(context.getString(R.string.pref_tracker_use_flex_mode), context.getResources().getBoolean(R.bool.def_flex_mode)); Log.i(TAG, "SMS: " + text); Tracker tracker = new Tracker(); if (!parseXexunTK102(text, tracker) && !parseJointechJT600(text, tracker) && !parseTK102Clone1(text, tracker) && !(parseFlexMode(text, tracker) && flexMode)) return; if (tracker.message != null) { tracker.message = tracker.message.trim(); if ("".equals(tracker.message)) tracker.message = null; } tracker.sender = Sender; if (!"".equals(tracker.sender)) { // Save tracker data TrackerDataAccess dataAccess = new TrackerDataAccess(context); dataAccess.updateTracker(tracker); try { Application application = Application.getApplication(); tracker = dataAccess.getTracker(tracker.sender);//get latest positon of tracker application.sendTrackerOnMap(dataAccess, tracker); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } dataAccess.close(); context.sendBroadcast(new Intent(Application.TRACKER_DATE_RECEIVED_BROADCAST)); // Show notification boolean notifications = prefs.getBoolean(context.getString(R.string.pref_tracker_notifications), context.getResources().getBoolean(R.bool.def_notifications)); if (notifications) { Intent i = new Intent("com.androzic.COORDINATES_RECEIVED"); i.putExtra("title", tracker.message != null ? tracker.message : tracker.name); i.putExtra("sender", tracker.name); i.putExtra("origin", context.getApplicationContext().getPackageName()); i.putExtra("lat", tracker.latitude); i.putExtra("lon", tracker.longitude); String msg = context.getString(R.string.notif_text, tracker.name); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle(context.getString(R.string.app_name)); if (tracker.message != null) builder.setContentText(tracker.name + ": " + tracker.message); else builder.setContentText(msg); PendingIntent contentIntent = PendingIntent.getBroadcast(context, (int) tracker._id, i, PendingIntent.FLAG_ONE_SHOT); builder.setContentIntent(contentIntent); builder.setSmallIcon(R.drawable.ic_stat_tracker); builder.setTicker(msg); builder.setWhen(tracker.time); int defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND; boolean vibrate = prefs.getBoolean(context.getString(R.string.pref_tracker_vibrate), context.getResources().getBoolean(R.bool.def_vibrate)); if (vibrate) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); builder.setAutoCancel(true); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int) tracker._id, notification); } // Conceal SMS boolean concealsms = prefs.getBoolean(context.getString(R.string.pref_tracker_concealsms), context.getResources().getBoolean(R.bool.def_concealsms)); if (concealsms) abortBroadcast(); } }
From source file:com.jieehd.villain.toolkit.stats.ReportingService.java
private void promptUser() { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent nI = new Intent(); nI.setComponent(new ComponentName(getPackageName(), AnonymousStats.class.getName())); PendingIntent pI = PendingIntent.getActivity(this, 0, nI, 0); Notification.Builder builder = new Notification.Builder(this).setAutoCancel(true) .setTicker("Annonymous Statistics").setContentIntent(pI).setWhen(0) .setContentTitle("Annonymous Statistics").setContentText("Enable Reporting"); nm.notify(1, builder.getNotification()); }
From source file:com.androzic.navigation.NavigationService.java
private void updateNavigationState(final int state) { if (state != STATE_STOPED && state != STATE_REACHED) { NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, getNotification()); }// ww w. j a v a2s . c o m sendBroadcast(new Intent(BROADCAST_NAVIGATION_STATE).putExtra("state", state)); Log.d(TAG, "State dispatched"); }
From source file:com.aniruddhc.acemusic.player.AsyncTasks.AsyncAutoGetAlbumArtTask.java
@Override public void onProgressUpdate(String... values) { super.onProgressUpdate(values); if (DIALOG_VISIBLE == true) { pd.setProgress(Integer.parseInt(values[1])); pd.setMessage(values[0]);/*w ww. ja v a 2s . c om*/ } //Update the notification. AutoFetchAlbumArtService.builder .setContentTitle(mContext.getResources().getString(R.string.downloading_missing_cover_art)); AutoFetchAlbumArtService.builder.setSmallIcon(R.drawable.notif_icon); AutoFetchAlbumArtService.builder.setContentInfo(null); AutoFetchAlbumArtService.builder.setContentText(null); AutoFetchAlbumArtService.builder.setProgress(dataURIsList.size(), currentProgress, false); AutoFetchAlbumArtService.notification = AutoFetchAlbumArtService.builder.build(); NotificationManager notifyManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); notifyManager.notify(AutoFetchAlbumArtService.NOTIFICATION_ID, AutoFetchAlbumArtService.notification); }
From source file:org.ohmage.sync.OhmageSyncAdapter.java
private void showInstallApkNotification(int id, Builder builder, Intent intent) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent resultPendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent).setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL); NotificationManager mNotificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(id, builder.build()); }
From source file:com.codepath.smartodo.activities.GeofenceActivity.java
private void sampleNotification() { // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // Set the notification contents builder.setSmallIcon(R.drawable.ic_notification) .setContentTitle(getString(R.string.geofence_transition_alert_title)) .setContentText(getString(R.string.geofence_transition_alert_text)); // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(0, builder.build()); }
From source file:org.kaoriha.phonegap.plugins.releasenotification.Notifier.java
private void pollBackground() { if (getToken() == null) { rescheduleAfterFail();//from w w w. j a va 2s. com return; } ToNextReleasePolling tp = new ToNextReleasePolling(); tp.poll(); if (tp.isFailed) { Log.d(TAG, "ToNextReleasePolling failed"); rescheduleAfterFail(); return; } CataloguePolling cp = new CataloguePolling(); cp.poll(); if (cp.isFailed) { Log.d(TAG, "CataloguePolling failed"); rescheduleAfterFail(); return; } if (!cp.isNew) { if (tp.toNextRelease == -1) { schedule(RESCHEDULE_NEXT_UNKNOWN_SPAN); } else { schedule(tp.toNextRelease); } Log.d(TAG, "CataloguePolling not new"); return; } String pushMessage; if (cp.catalogue.has(CATALOGUE_PUSH_MESSAGE_KEY)) { try { pushMessage = cp.catalogue.getString(CATALOGUE_PUSH_MESSAGE_KEY); } catch (JSONException e) { Log.i(TAG, "pollBackground()", e); pushMessage = pref.getString(SPKEY_DEFAULT_PUSH_MESSAGE, null); } } else { pushMessage = pref.getString(SPKEY_DEFAULT_PUSH_MESSAGE, null); } String lastSid; try { lastSid = getLastSid(cp.catalogue); if (lastSid.equals(pref.getString(SPKEY_LAST_SID, null))) { schedule(tp.toNextRelease); } } catch (JSONException e) { Log.d(TAG, "bad JSON", e); rescheduleAfterFail(); return; } int icon = R.drawable.notification; Notification n = new Notification(icon, pushMessage, System.currentTimeMillis()); n.flags = Notification.FLAG_AUTO_CANCEL; Intent i = new Intent(ctx, FlowerflowerActivity.class); i.setAction(Intent.ACTION_MAIN); i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(ctx, 0, i, 0); n.setLatestEventInfo(ctx.getApplicationContext(), pref.getString(SPKEY_TITLE, null), pushMessage, pi); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, n); pref.edit().putString(SPKEY_LAST_SID, lastSid).putString(SPKEY_LAST_CATALOGUE_ETAG, cp.etag).commit(); clearFailRepeat(); schedule(tp.toNextRelease); Log.d(TAG, "pollBackground() success"); }
From source file:com.BeatYourRecord.AssignmentSyncService.java
public void sendNotification(String ytdDomain, String assignmentId) { int notificationId = 1; Intent assignmentIntent = new Intent(this, DetailsActivity.class); assignmentIntent.putExtra(DbHelper.YTD_DOMAIN, ytdDomain); assignmentIntent.putExtra(DbHelper.ASSIGNMENT_ID, assignmentId); assignmentIntent.putExtra("notificationId", notificationId); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, assignmentIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification n = new Notification(R.drawable.icon, "Update from YouTube Direct", System.currentTimeMillis()); n.setLatestEventInfo(getApplicationContext(), "Update from YouTube Direct", "For " + SettingActivity.getYtdDomains(this).get(this.ytdDomain), pendingIntent); n.defaults |= Notification.DEFAULT_LIGHTS; nm.notify(notificationId, n); }