Java Code Examples for android.support.v4.app.NotificationManagerCompat#notify()

The following examples show how to use android.support.v4.app.NotificationManagerCompat#notify() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyncDataService.java    From SEAL-Demo with MIT License 6 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (REFRESH_ITEMS_ACTION.equals(action)) {
            Log.d(TAG, "Refresh items START");
            Analytics.trackEvent(TAG + " Refresh run items START");
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
            notificationManager.notify(NOTIFICATION_ID, buildNotification("AsureRun", "Syncing data...", R.drawable.ic_tracking, null));
            handleRefreshItems(notificationManager, false);
        } else if (DELETE_DATA_ON_FIRST_START_ACTION.equals(action)) {
            Log.d(TAG, "Delete data on first start");
            Analytics.trackEvent(TAG + " Delete data on first start");
            handleDeleteDataOnFirstStart();
        } else if (SEND_ITEM_ACTION.equals(action)) {
            Log.d(TAG, "Sending data on server");
            handleSendDataOnServer();
        }
    }
}
 
Example 2
Source File: LifeformDetectedReceiver.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  // Get the lifeform details from the intent.
  String type = intent.getStringExtra(EXTRA_LIFEFORM_NAME);
  double lat = intent.getDoubleExtra(EXTRA_LATITUDE, Double.NaN);
  double lng = intent.getDoubleExtra(EXTRA_LONGITUDE, Double.NaN);

  if (type.equals(FACE_HUGGER)) {
    NotificationManagerCompat notificationManager =
      NotificationManagerCompat.from(context);

    NotificationCompat.Builder builder =
      new NotificationCompat.Builder(context);

    builder.setSmallIcon(R.drawable.ic_alien)
      .setContentTitle("Face Hugger Detected")
      .setContentText(Double.isNaN(lat) || Double.isNaN(lng) ?
                        "Location Unknown" :
                        "Located at " + lat + "," + lng);

    notificationManager.notify(NOTIFICATION_ID, builder.build());
  }
}
 
Example 3
Source File: MainService.java    From android-play-games-in-motion with Apache License 2.0 6 votes vote down vote up
/**
 * Builds and posts a notification from a set of options.
 * @param options The options to build the notification.
 */
public void postActionNotification(NotificationOptions options) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(options.getSmallIconResourceId());
    builder.setContentTitle(options.getTitle());
    builder.setContentText(options.getContent());
    builder.setDefaults(options.getNotificationDefaults());
    builder.setPriority(options.getNotificationPriority());
    builder.setVibrate(options.getVibratePattern());
    if (options.getActions() != null) {
        for (NotificationCompat.Action action : options.getActions()) {
            builder.addAction(action);
        }
    }
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(this);
    notificationManager.notify(options.getNotificationId(), builder.build());
}
 
Example 4
Source File: MyActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
private void listing11_17(Context context) {
  NotificationManagerCompat notificationManager =
    NotificationManagerCompat.from(this);

  // Listing 11-17: Creating and posting a Notification
  final int NEW_MESSAGE_ID = 0;
  createMessagesNotificationChannel(context);

  NotificationCompat.Builder builder = new NotificationCompat.Builder(
    context, MESSAGES_CHANNEL);

  // These would be dynamic in a real app
  String title = "Reto Meier";
  String text = "Interested in a new book recommendation?" +
                  " I have one you should check out!";

  builder.setSmallIcon(R.drawable.ic_notification)
    .setContentTitle(title)
    .setContentText(text);

  notificationManager.notify(NEW_MESSAGE_ID, builder.build());
}
 
Example 5
Source File: NotificationHelper.java    From KUAS-AP-Material with MIT License 6 votes vote down vote up
/**
 * Create a notification
 *
 * @param context The application context
 * @param title   Notification title
 * @param content Notification content.
 */
public static void createNotification(final Context context, final String title,
                                      final String content, int id) {
	NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

	NotificationCompat.Builder builder =
			new NotificationCompat.Builder(context).setContentTitle(title)
					.setStyle(new NotificationCompat.BigTextStyle().bigText(content))
					.setColor(ContextCompat.getColor(context, R.color.main_theme))
					.extend(new NotificationCompat.WearableExtender()
							.setHintShowBackgroundOnly(true)).setContentText(content)
					.setAutoCancel(true).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
					.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0))
					.setSmallIcon(R.drawable.ic_stat_kuas_ap);

	builder.setVibrate(vibrationPattern);
	builder.setLights(Color.GREEN, 800, 800);
	builder.setDefaults(Notification.DEFAULT_SOUND);

	notificationManager.notify(id, builder.build());
}
 
Example 6
Source File: PlumbleMessageNotification.java    From Plumble with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows the notification with the provided message.
 * If the notification is already shown, append the message to the existing notification.
 * @param message The message to notify the user about.
 */
public void show(IMessage message) {
    mUnreadMessages.add(message);

    NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
    style.setBigContentTitle(mContext.getString(R.string.notification_unread_many, mUnreadMessages.size()));
    for (IMessage m : mUnreadMessages) {
        String line = mContext.getString(R.string.notification_message, m.getActorName(), m.getMessage());
        style.addLine(line);
    }

    Intent channelListIntent = new Intent(mContext, PlumbleActivity.class);
    channelListIntent.putExtra(PlumbleActivity.EXTRA_DRAWER_FRAGMENT, DrawerAdapter.ITEM_SERVER);
    // FLAG_CANCEL_CURRENT ensures that the extra always gets sent.
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, channelListIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setSmallIcon(R.drawable.ic_stat_notify)
            .setContentIntent(pendingIntent)
            .setAutoCancel(true)
            .setTicker(message.getActorName())
            .setContentTitle(message.getActorName())
            .setContentText(message.getMessage())
            .setVibrate(VIBRATION_PATTERN)
            .setStyle(style);

    if (mUnreadMessages.size() > 0)
        builder.setNumber(mUnreadMessages.size());

    final NotificationManagerCompat manager = NotificationManagerCompat.from(mContext);
    Notification notification = builder.build();
    manager.notify(NOTIFICATION_ID, notification);
}
 
Example 7
Source File: NotificationService.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private void notify(String tag, int id, Notification notification) {
    final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
    try {
        notificationManager.notify(tag, id, notification);
    } catch (RuntimeException e) {
        Log.d(Config.LOGTAG, "unable to make notification", e);
    }
}
 
Example 8
Source File: MainActivity.java    From wearable with Apache License 2.0 5 votes vote down vote up
void addbuttonNoti() {
	Log.i("main", "addbutton noti");
	//create the intent to launch the notiactivity, then the pentingintent.
	Intent viewIntent = new Intent(this, NotiActivity.class);
	viewIntent.putExtra("NotiID", "Notification ID is " + notificationID);
	
	PendingIntent viewPendingIntent =
	        PendingIntent.getActivity(this, 0, viewIntent, 0);
	
	// we are going to add an intent to open the camera here.
	Intent cameraIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
	PendingIntent cameraPendingIntent =
	        PendingIntent.getActivity(this, 0, cameraIntent, 0);
	

	//Now create the notification.  We must use the NotificationCompat or it will not work on the wearable.
	NotificationCompat.Builder notificationBuilder =
	        new NotificationCompat.Builder(this)
	        .setSmallIcon(R.drawable.ic_launcher)
	        .setContentTitle("add button Noti")
	        .setContentText("swipe left to open camera.")
	        .setContentIntent(viewPendingIntent)
	        .addAction(R.drawable.ic_action_time,
               "take Picutre", cameraPendingIntent);

	// Get an instance of the NotificationManager service
	NotificationManagerCompat notificationManager =
	        NotificationManagerCompat.from(this);

	// Build the notification and issues it with notification manager.
	notificationManager.notify(notificationID, notificationBuilder.build());
	notificationID++;
	
}
 
Example 9
Source File: MoveService.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void createSummaryNotificationForFailed() {
    Notification summaryNotification =
            new NotificationCompat.Builder(this, CHANNEL_ID)
                    .setContentTitle(getString(R.string.operation_failed))
                    //set content text to support devices running API level < 24
                    .setContentText(getString(R.string.operation_failed))
                    .setSmallIcon(android.R.drawable.stat_sys_warning)
                    .setGroup(OPERATION_FAILED_GROUP)
                    .setGroupSummary(true)
                    .setAutoCancel(true)
                    .build();

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(OPERATION_FAILED_NOTIFICATION_ID, summaryNotification);
}
 
Example 10
Source File: DownloadService.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void createSummaryNotificationForFinished() {
    Notification summaryNotification =
            new NotificationCompat.Builder(this, CHANNEL_ID)
                    .setContentTitle(getString(R.string.download_complete))
                    //set content text to support devices running API level < 24
                    .setContentText(getString(R.string.download_complete))
                    .setSmallIcon(android.R.drawable.stat_sys_download_done)
                    .setGroup(DOWNLOAD_FINISHED_GROUP)
                    .setGroupSummary(true)
                    .setAutoCancel(true)
                    .build();

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(DOWNLOAD_FINISHED_NOTIFICATION_ID, summaryNotification);
}
 
Example 11
Source File: DownloadService.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void showDownloadFailedNotification(int notificationId, String contentText) {
    createSummaryNotificationForFailed();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(android.R.drawable.stat_sys_warning)
            .setContentTitle(getString(R.string.download_failed))
            .setContentText(contentText)
            .setGroup(DOWNLOAD_FAILED_GROUP)
            .setPriority(NotificationCompat.PRIORITY_LOW);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(notificationId, builder.build());
}
 
Example 12
Source File: DownloadService.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void createSummaryNotificationForFailed() {
    Notification summaryNotification =
            new NotificationCompat.Builder(this, CHANNEL_ID)
                    .setContentTitle(getString(R.string.download_failed))
                    //set content text to support devices running API level < 24
                    .setContentText(getString(R.string.download_failed))
                    .setSmallIcon(android.R.drawable.stat_sys_warning)
                    .setGroup(DOWNLOAD_FAILED_GROUP)
                    .setGroupSummary(true)
                    .setAutoCancel(true)
                    .build();

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(FAILED_DOWNLOAD_NOTIFICATION_ID, summaryNotification);
}
 
Example 13
Source File: SyncService.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void showFailedNotification(String title, String content, int notificationId) {
    createSummaryNotificationForFailed();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(android.R.drawable.stat_sys_warning)
            .setContentTitle(title)
            .setContentText(content)
            .setGroup(OPERATION_FAILED_GROUP)
            .setPriority(NotificationCompat.PRIORITY_LOW);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(notificationId, builder.build());

}
 
Example 14
Source File: Builder.java    From Pugnotification with Apache License 2.0 4 votes vote down vote up
protected Notification notificationNotify(String tag, int identifier) {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(PugNotification.mSingleton.mContext);
    notificationManager.notify(tag, identifier, notification);
    return notification;
}
 
Example 15
Source File: PlumbleReconnectNotification.java    From Plumble with GNU General Public License v3.0 4 votes vote down vote up
public void show(String error, boolean autoReconnect) {
    IntentFilter filter = new IntentFilter();
    filter.addAction(BROADCAST_DISMISS);
    filter.addAction(BROADCAST_RECONNECT);
    filter.addAction(BROADCAST_CANCEL_RECONNECT);
    try {
        mContext.registerReceiver(mNotificationReceiver, filter);
    } catch (IllegalArgumentException e) {
        // Thrown if receiver is already registered.
        e.printStackTrace();
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    builder.setSmallIcon(R.drawable.ic_stat_notify);
    builder.setPriority(NotificationCompat.PRIORITY_MAX);
    builder.setDefaults(NotificationCompat.DEFAULT_VIBRATE | NotificationCompat.DEFAULT_LIGHTS);
    builder.setContentTitle(mContext.getString(R.string.plumbleDisconnected));
    builder.setContentText(error);
    builder.setTicker(mContext.getString(R.string.plumbleDisconnected));

    Intent dismissIntent = new Intent(BROADCAST_DISMISS);
    builder.setDeleteIntent(PendingIntent.getBroadcast(mContext, 2, dismissIntent,
            PendingIntent.FLAG_CANCEL_CURRENT));

    if (autoReconnect) {
        Intent cancelIntent = new Intent(BROADCAST_CANCEL_RECONNECT);
        builder.addAction(R.drawable.ic_action_delete_dark,
                mContext.getString(R.string.cancel_reconnect),
                PendingIntent.getBroadcast(mContext, 2,
                        cancelIntent, PendingIntent.FLAG_CANCEL_CURRENT));
        builder.setOngoing(true);
    } else {
        Intent reconnectIntent = new Intent(BROADCAST_RECONNECT);
        builder.addAction(R.drawable.ic_action_move,
                mContext.getString(R.string.reconnect),
                PendingIntent.getBroadcast(mContext, 2,
                        reconnectIntent, PendingIntent.FLAG_CANCEL_CURRENT));
    }

    NotificationManagerCompat nmc = NotificationManagerCompat.from(mContext);
    nmc.notify(NOTIFICATION_ID, builder.build());
}
 
Example 16
Source File: SimpleUpdateChecker.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
private void checkUpdate(JSONObject updateObject, Context context, String jsonSource) throws JSONException {
    if (context == null) {
        context = App.getContext();
    }
    final int currentVersionCode = BuildConfig.VERSION_CODE;
    final int versionCode = Integer.parseInt(updateObject.getString("version_code"));

    if (versionCode > currentVersionCode) {
        final String versionName = updateObject.getString("version_name");


        String channelId = "forpda_channel_updates";
        String channelName = context.getString(R.string.updater_notification_title);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
            NotificationManager manager = context.getSystemService(NotificationManager.class);
            if (manager != null) {
                manager.createNotificationChannel(channel);
            }
        }


        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, channelId);

        NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context);

        mBuilder.setSmallIcon(R.drawable.ic_notify_mention);

        mBuilder.setContentTitle(context.getString(R.string.updater_notification_title));
        mBuilder.setContentText(String.format(context.getString(R.string.updater_notification_content_VerName), versionName));
        mBuilder.setChannelId(channelId);


        Intent notifyIntent = new Intent(context, UpdateCheckerActivity.class);
        //notifyIntent.setData(Uri.parse(createIntentUrl(notificationEvent)));
        notifyIntent.putExtra(UpdateCheckerActivity.JSON_SOURCE, jsonSource);
        notifyIntent.setAction(Intent.ACTION_VIEW);
        PendingIntent notifyPendingIntent = PendingIntent.getActivity(context, 0, notifyIntent, 0);
        mBuilder.setContentIntent(notifyPendingIntent);

        mBuilder.setAutoCancel(true);

        mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
        mBuilder.setCategory(NotificationCompat.CATEGORY_EVENT);


        int defaults = 0;
        /*if (Preferences.Notifications.Main.isSoundEnabled()) {
            defaults |= NotificationCompat.DEFAULT_SOUND;
        }*/
        if (Preferences.Notifications.Main.isVibrationEnabled(null)) {
            defaults |= NotificationCompat.DEFAULT_VIBRATE;
        }
        mBuilder.setDefaults(defaults);

        mNotificationManager.notify(versionCode, mBuilder.build());
    }
}
 
Example 17
Source File: Notifications.java    From HAPP with GNU General Public License v3.0 4 votes vote down vote up
public static void updateCard(Realm realm){
    Log.d(TAG, "updateCard: START");
    
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainApp.instance());

    if (prefs.getBoolean("summary_notification", true)) {

        //TempBasal lastTempBasal = TempBasal.last();
        Pump pump       = new Pump(new Profile(new Date()), realm);
        String title    = pump.displayBasalDesc(false);
        String msg      = pump.displayCurrentBasal(false) + " " + pump.displayTempBasalMinsLeft();

        Intent intent_open_activity = new Intent(MainApp.instance(),MainActivity.class);
        PendingIntent pending_intent_open_activity = PendingIntent.getActivity(MainApp.instance(), 3, intent_open_activity, PendingIntent.FLAG_UPDATE_CURRENT);

        Intent intent_run_aps = new Intent();
        intent_run_aps.setAction(Intents.NOTIFICATION_UPDATE);
        intent_run_aps.putExtra("NOTIFICATION_TYPE", "RUN_OPENAPS");
        PendingIntent pending_intent_run_aps = PendingIntent.getBroadcast(MainApp.instance(), 5, intent_run_aps, PendingIntent.FLAG_CANCEL_CURRENT);

        Intent intent_cancel_tbr = new Intent();
        intent_cancel_tbr.setAction(Intents.NOTIFICATION_UPDATE);
        intent_cancel_tbr.putExtra("NOTIFICATION_TYPE", "CANCEL_TBR");
        PendingIntent pending_intent_cancel_tbr = PendingIntent.getBroadcast(MainApp.instance(), 6, intent_cancel_tbr, PendingIntent.FLAG_CANCEL_CURRENT);

        Bitmap bitmap = Bitmap.createBitmap(320, 320, Bitmap.Config.ARGB_8888);
        bitmap.eraseColor(MainApp.instance().getResources().getColor(R.color.secondary_text_light));

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainApp.instance());
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
        notificationBuilder.setColor(MainApp.instance().getResources().getColor(R.color.primary));
        notificationBuilder.extend(new NotificationCompat.WearableExtender().setBackground(bitmap));
        notificationBuilder.setContentTitle(title);
        notificationBuilder.setContentText(msg);
        notificationBuilder.setContentIntent(pending_intent_open_activity);
        notificationBuilder.setPriority(Notification.PRIORITY_MIN);
        notificationBuilder.setCategory(Notification.CATEGORY_STATUS);
        notificationBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
        notificationBuilder.addAction(R.drawable.ic_play_dark, "Run APS", pending_intent_run_aps);
        if(pump.temp_basal_active) notificationBuilder.addAction(R.drawable.ic_stop, "Cancel TBR", pending_intent_cancel_tbr);

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(MainApp.instance());
        notificationManager.notify(UPDATE_CARD, notificationBuilder.build());
    }
    Log.d(TAG, "updateCard: FINISH");
}
 
Example 18
Source File: MainActivity.java    From watchpresenter with Apache License 2.0 4 votes vote down vote up
public void launchNotification(){
// Build intent for notification content
        Intent viewIntent = new Intent(this, SendMessageReceiver.class);
        viewIntent.setAction("com.zuluindia.watchpresenter.SEND_MESSAGE");
        viewIntent.putExtra(Constants.EXTRA_MESSAGE, Constants.NEXT_SLIDE_MESSAGE);
        PendingIntent viewPendingIntent =
                PendingIntent.getBroadcast(this, 0, viewIntent, 0);


        Intent dismissedIntent = new Intent(ACTION_STOP_MONITORING);
        PendingIntent dismissedPendingIntent =
                PendingIntent.getBroadcast(this, 0, dismissedIntent, 0);


        Intent resultIntent = new Intent(this, MainActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Action action = new NotificationCompat.Action.Builder(
                com.zuluindia.watchpresenter.R.drawable.ic_stat_ic_action_forward_blue,
                getString(R.string.nextSlide), viewPendingIntent).build();
        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(com.zuluindia.watchpresenter.R.drawable.ic_launcher)
                        .setContentTitle(getResources().getString(R.string.notificationTitle))
                        .setContentText(getResources().getString(R.string.notificationMessage))
                        .setDeleteIntent(dismissedPendingIntent)
                        .addAction(action)
                        .setContentIntent(resultPendingIntent)
                        .extend(new NotificationCompat.WearableExtender()
                                .setContentAction(0));

// Get an instance of the NotificationManager service
        NotificationManagerCompat notificationManager =
                NotificationManagerCompat.from(this);

// Build the notification and issues it with notification manager.
        notificationManager.notify(PRESENTING_NOTIFICATION_ID, notificationBuilder.build());
        Intent objIntent = new Intent(this, MonitorVolumeKeyPress.class);
        startService(objIntent);
        //Send warm-up message
        Intent i = new Intent(SendMessageReceiver.INTENT);
        i.putExtra(Constants.EXTRA_MESSAGE, Constants.WARMUP_MESSAGE);
        sendBroadcast(i);
    }
 
Example 19
Source File: NotificationService.java    From good-weather with GNU General Public License v3.0 4 votes vote down vote up
private void weatherNotification(Weather weather) {
    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent launchIntent = PendingIntent.getActivity(this, 0, intent, 0);

    String temperatureScale = Utils.getTemperatureScale(this);
    String speedScale = Utils.getSpeedScale(this);

    String temperature = String.format(Locale.getDefault(), "%.1f",
                                       weather.temperature.getTemp());

    String wind = getString(R.string.wind_label, String.format(Locale.getDefault(),
                                                               "%.1f",
                                                               weather.wind.getSpeed()),
                            speedScale);
    String humidity = getString(R.string.humidity_label,
                                String.valueOf(weather.currentCondition.getHumidity()),
                                getString(R.string.percent_sign));
    String pressure = getString(R.string.pressure_label,
                                String.format(Locale.getDefault(), "%.1f",
                                              weather.currentCondition.getPressure()),
                                getString(R.string.pressure_measurement));
    String cloudiness = getString(R.string.pressure_label,
                                  String.valueOf(weather.cloud.getClouds()),
                                  getString(R.string.percent_sign));

    StringBuilder notificationText = new StringBuilder(wind)
            .append("  ")
            .append(humidity)
            .append("  ")
            .append(pressure)
            .append("  ")
            .append(cloudiness);

    Notification notification = new NotificationCompat.Builder(this)
            .setContentIntent(launchIntent)
            .setSmallIcon(R.drawable.small_icon)
            .setTicker(temperature
                               + temperatureScale
                               + "  "
                               + weather.location.getCityName()
                               + ", "
                               + weather.location.getCountryCode())
            .setContentTitle(temperature
                                     + temperatureScale
                                     + "  "
                                     + weather.currentWeather.getDescription())
            .setContentText(notificationText)
            .setVibrate(isVibrateEnabled())
            .setAutoCancel(true)
            .build();

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(0, notification);
}
 
Example 20
Source File: Builder.java    From ZadakNotification with MIT License 4 votes vote down vote up
protected Notification notificationNotify(int identifier) {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ZadakNotification.mSingleton.mContext);
    notificationManager.notify(identifier, notification);
    return notification;
}