Java Code Examples for android.support.v4.app.NotificationCompat#BigTextStyle

The following examples show how to use android.support.v4.app.NotificationCompat#BigTextStyle . 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: RMBTLoopService.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
private void setNotificationText(NotificationCompat.Builder builder)
{
    final Resources res = getResources();
    
    final long now = SystemClock.elapsedRealtime();
    final long lastTestDelta = loopModeResults.getLastTestTime() == 0 ? 0 : now - loopModeResults.getLastTestTime();
    
    final String elapsedTimeString = LoopModeTriggerItem.formatSeconds(Math.round(lastTestDelta / 1000), 1);
    
    final CharSequence textTemplate = res.getText(R.string.loop_notification_text_without_stop);
    final CharSequence text = MessageFormat.format(textTemplate.toString(), 
    		loopModeResults.getNumberOfTests(), elapsedTimeString, Math.round(loopModeResults.getLastDistance()));
    builder.setContentText(text);
    
    if (bigTextStyle == null)
    {
        bigTextStyle = (new NotificationCompat.BigTextStyle());
        builder.setStyle(bigTextStyle);
    }
    
    bigTextStyle.bigText(text);
}
 
Example 2
Source File: UnreadNotificationsService.java    From ghwatch with Apache License 2.0 6 votes vote down vote up
private android.app.Notification buildAndroidNotificationBundledStyleDetail(Notification n) {
  NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
          .setContentTitle(n.getRepositoryFullName())
          .setContentText(n.getSubjectTitle())
          .setSmallIcon(R.drawable.notification)
          .setCategory(android.app.Notification.CATEGORY_SOCIAL)
          .setPriority(android.app.Notification.PRIORITY_DEFAULT)
          .setColor(notificationColor)
          .setGroup(ANDROID_NOTIFICATION_GROUP_KEY);
  NotificationCompat.BigTextStyle btStyle = new NotificationCompat.BigTextStyle();
  btStyle.bigText(n.getSubjectTitle());
  btStyle.setSummaryText(n.getRepositoryFullName());
  mBuilder.setStyle(btStyle);
  Bitmap b = ImageLoader.getInstance(context).loadImageWithFileLevelCache(n.getRepositoryAvatarUrl());
  if (b != null) {
    mBuilder.setLargeIcon(b);
  }
  if (n.getUpdatedAt() != null) {
    mBuilder.setWhen(n.getUpdatedAt().getTime()).setShowWhen(true);
  }
  buildNotificationActionMarkOneAsRead(mBuilder, n, true);
  buildNotificationActionMuteThreadOne(mBuilder, n, true);
  buildNotificationSetContetnIntentShowDetail(mBuilder, n, true);
  buildNotificationDeletedIntent(mBuilder,n,true);
  return mBuilder.build();
}
 
Example 3
Source File: MainActivity.java    From NoiseCapture with GNU General Public License v3.0 6 votes vote down vote up
protected void displayCommunityMapNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(MeasurementService.getNotificationIcon())
            .setContentTitle(getString(R.string.notification_goto_community_map_title))
            .setContentText(getString(R.string.notification_goto_community_map))
            .setAutoCancel(true);
    NotificationCompat.BigTextStyle bigTextStyle =
            new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(getString(R.string.notification_goto_community_map_title));
    bigTextStyle.bigText(getString(R.string.notification_goto_community_map));
    builder.setStyle(bigTextStyle);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://noise-planet.org/map_noisecapture"));
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(this);
    stackBuilder.addNextIntent(intent);
    builder.setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
    NotificationManager mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    mNM.notify(NOTIFICATION_MAP, builder.build());
}
 
Example 4
Source File: NotificationHelpers.java    From io.appium.settings with Apache License 2.0 5 votes vote down vote up
public static Notification getNotification(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        createChannel(context);
    }
    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(CHANNEL_NAME);
    bigTextStyle.bigText(CHANNEL_DESCRIPTION);
    return new NotificationCompat.Builder(context, CHANNEL_ID)
            .setStyle(bigTextStyle)
            .setWhen(System.currentTimeMillis())
            .setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
            .build();
}
 
Example 5
Source File: MainActivity.java    From wearable with Apache License 2.0 5 votes vote down vote up
void bigTextNoti() {
	//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);

	BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
	bigStyle.bigText("Big text style.\n"
			+ "We should have more room to add text for the user to read, instead of a short message.");

	
	//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("Simple Noti")
	        .setContentText("This is a simple notification")
	        .setContentIntent(viewPendingIntent)
	        .setStyle(bigStyle);

	// 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 6
Source File: WearList.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void showMultiPageWearNotification() {
	NotificationCompat.Builder notificationBuilder =
			new NotificationCompat.Builder(getActivity())
					.setSmallIcon( R.drawable.ic_launcher )
					.setContentTitle( "Page 1" )
					.setContentText( "Short message" );

	NotificationCompat.BigTextStyle additionalPageStyle = new NotificationCompat.BigTextStyle();
	additionalPageStyle.setBigContentTitle( "Page 2" );

	Notification secondPageNotification =
			new NotificationCompat.Builder( getActivity() )
					.setStyle( additionalPageStyle )
					.build();

	additionalPageStyle.setBigContentTitle( "Page 3" );
	Notification thirdPageNotification =
			new NotificationCompat.Builder( getActivity() )
					.setStyle( additionalPageStyle )
					.build();

	additionalPageStyle.setBigContentTitle( "Page 4" );

	Notification fourthPageNotification =
			new NotificationCompat.Builder( getActivity() )
					.setStyle( additionalPageStyle )
					.build();

	List<Notification> list = new ArrayList<Notification>();
	list.add( secondPageNotification );
	list.add( thirdPageNotification );
	list.add( fourthPageNotification );
	Notification twoPageNotification =
			new WearableNotifications.Builder(notificationBuilder)
					.addPages(list)
					.build();

	mNotificationManager.notify( ++notificationId, twoPageNotification );
}
 
Example 7
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
    style.bigText(context.getString(R.string.big_text_example_big_text));
    style.setBigContentTitle(context.getString(R.string.big_text_example_title));
    style.setSummaryText(context.getString(R.string.big_text_example_summary_text));

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setStyle(style);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 8
Source File: ONotificationBuilder.java    From framework with GNU Affero General Public License v3.0 5 votes vote down vote up
private void init() {
    mNotificationManager = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationBuilder = new NotificationCompat.Builder(mContext);
    mNotificationBuilder.setContentTitle(title);
    mNotificationBuilder.setContentText(text);
    if (bigText == null)
        mNotificationBuilder.setContentInfo(text);
    if (withLargeIcon()) {
        mNotificationBuilder.setSmallIcon(small_icon);
        Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(), this.icon);
        Bitmap newIcon = Bitmap.createBitmap(icon.getWidth(), icon.getHeight(), icon.getConfig());
        Canvas canvas = new Canvas(newIcon);
        canvas.drawColor(OResource.color(mContext, R.color.theme_primary));
        canvas.drawBitmap(icon, 0, 0, null);
        mNotificationBuilder.setLargeIcon(newIcon);
    } else {
        mNotificationBuilder.setSmallIcon(icon);
    }
    mNotificationBuilder.setAutoCancel(mAutoCancel);
    mNotificationBuilder.setOngoing(mOnGoing);
    mNotificationBuilder.setColor(OResource.color(mContext, notification_color));
    if (bigText != null) {
        NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle();
        notiStyle.setBigContentTitle(title);
        notiStyle.setSummaryText(text);
        notiStyle.bigText(bigText);
        mNotificationBuilder.setStyle(notiStyle);
    }
    if (bigPictureStyle != null) {
        mNotificationBuilder.setStyle(new NotificationCompat.BigPictureStyle()
                .bigPicture(bigPictureStyle));
    }

    if (maxProgress != -1) {
        mNotificationBuilder.setProgress(maxProgress, currentProgress, indeterminate);
    }
}
 
Example 9
Source File: BigTextBuilder.java    From NotifyUtil with Apache License 2.0 5 votes vote down vote up
@Override
public void build() {
    super.build();
    NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle();
    textStyle.setBigContentTitle(contentTitle).bigText(contentText).setSummaryText(summaryText);
    cBuilder.setStyle(textStyle);
}
 
Example 10
Source File: ONotificationBuilder.java    From hr with GNU Affero General Public License v3.0 5 votes vote down vote up
private void init() {
    mNotificationManager = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationBuilder = new NotificationCompat.Builder(mContext);
    mNotificationBuilder.setContentTitle(title);
    mNotificationBuilder.setContentText(text);
    if (bigText == null)
        mNotificationBuilder.setContentInfo(text);
    if (withLargeIcon()) {
        mNotificationBuilder.setSmallIcon(small_icon);
        Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(), this.icon);
        Bitmap newIcon = Bitmap.createBitmap(icon.getWidth(), icon.getHeight(), icon.getConfig());
        Canvas canvas = new Canvas(newIcon);
        canvas.drawColor(OResource.color(mContext, R.color.theme_primary));
        canvas.drawBitmap(icon, 0, 0, null);
        mNotificationBuilder.setLargeIcon(newIcon);
    } else {
        mNotificationBuilder.setSmallIcon(icon);
    }
    mNotificationBuilder.setAutoCancel(mAutoCancel);
    mNotificationBuilder.setOngoing(mOnGoing);
    mNotificationBuilder.setColor(OResource.color(mContext, notification_color));
    if (bigText != null) {
        NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle();
        notiStyle.setBigContentTitle(title);
        notiStyle.setSummaryText(text);
        notiStyle.bigText(bigText);
        mNotificationBuilder.setStyle(notiStyle);
    }
    if (bigPictureStyle != null) {
        mNotificationBuilder.setStyle(new NotificationCompat.BigPictureStyle()
                .bigPicture(bigPictureStyle));
    }

    if (maxProgress != -1) {
        mNotificationBuilder.setProgress(maxProgress, currentProgress, indeterminate);
    }
}
 
Example 11
Source File: NotificationHelper.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
private Notification createInstalledSummaryNotification(ArrayList<AppUpdateStatusManager.AppUpdateStatus> installed) {
    String title = context.getResources().getQuantityString(R.plurals.notification_summary_installed,
            installed.size(), installed.size());
    StringBuilder text = new StringBuilder();

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(title);

    for (int i = 0; i < MAX_INSTALLED_TO_SHOW && i < installed.size(); i++) {
        AppUpdateStatusManager.AppUpdateStatus entry = installed.get(i);
        App app = entry.app;
        if (text.length() > 0) {
            text.append(", ");
        }
        text.append(app.name);
    }
    bigTextStyle.bigText(text);
    if (installed.size() > MAX_INSTALLED_TO_SHOW) {
        int diff = installed.size() - MAX_INSTALLED_TO_SHOW;
        bigTextStyle.setSummaryText(context.getResources().getQuantityString(R.plurals.notification_summary_more,
                diff, diff));
    }

    // Intent to open main app list
    Intent intentObject = new Intent(context, MainActivity.class);
    PendingIntent piAction = PendingIntent.getActivity(context, 0, intentObject, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(context)
                    .setAutoCancel(!useStackedNotifications())
                    .setSmallIcon(R.drawable.ic_notification)
                    .setColor(ContextCompat.getColor(context, R.color.fdroid_blue))
                    .setContentTitle(title)
                    .setContentText(text)
                    .setContentIntent(piAction)
                    .setLocalOnly(true)
                    .setVisibility(NotificationCompat.VISIBILITY_SECRET);
    if (useStackedNotifications()) {
        builder.setGroup(GROUP_INSTALLED)
                .setGroupSummary(true);
    }
    Intent intentDeleted = new Intent(BROADCAST_NOTIFICATIONS_ALL_INSTALLED_CLEARED);
    intentDeleted.setClass(context, NotificationBroadcastReceiver.class);
    PendingIntent piDeleted = PendingIntent.getBroadcast(context, 0, intentDeleted, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(piDeleted);
    return builder.build();
}
 
Example 12
Source File: CheckForMail.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onPostExecute(List<Submission> messages) {
    if (messages != null) {
        if (!messages.isEmpty()) {
            NotificationManager notificationManager =
                    (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
            for (Submission s : messages) {
                Intent readIntent = new Intent(c, OpenContent.class);
                readIntent.putExtra(OpenContent.EXTRA_URL,
                        "https://reddit.com" + s.getPermalink());
                readIntent.setAction(s.getTitle());
                PendingIntent readPI = PendingIntent.getActivity(c,
                        (int) (s.getCreated().getTime() / 1000), readIntent,
                        0);

                Intent cancelIntent = new Intent(c, CancelSubNotifs.class);
                cancelIntent.putExtra(CancelSubNotifs.EXTRA_SUB, s.getSubredditName());
                PendingIntent cancelPi = PendingIntent.getActivity(c,  (int)s.getCreated().getTime() / 1000, cancelIntent,
                        0);


                NotificationCompat.BigTextStyle notiStyle =
                        new NotificationCompat.BigTextStyle();
                notiStyle.setBigContentTitle("/r/" + s.getSubredditName());

                notiStyle.bigText(Html.fromHtml(s.getTitle() + " " + c.getString(
                        R.string.submission_properties_seperator_comments)) + " "
                        + s.getAuthor());


                Notification notification =
                        new NotificationCompat.Builder(c).setContentIntent(readPI)
                                .setSmallIcon(R.drawable.notif)
                                .setTicker(c.getString(
                                        R.string.sub_post_notifs_notification_title,
                                        s.getSubredditName()))
                                .setWhen(System.currentTimeMillis())
                                .setAutoCancel(true)
                                .setChannelId(Reddit.CHANNEL_SUBCHECKING)
                                .setContentTitle("/r/"
                                        + s.getSubredditName()
                                        + " " + c.getString(
                                        R.string.submission_properties_seperator_comments) + " "
                                        + Html.fromHtml(s.getTitle()))
                                .setContentText(Html.fromHtml(s.getTitle()) + " " + c.getString(
                                        R.string.submission_properties_seperator_comments) + " "
                                        + s.getAuthor())
                                .setColor(Palette.getColor(s.getSubredditName()))
                                .setStyle(notiStyle)
                                .addAction(R.drawable.close, c.getString(
                                        R.string.sub_post_notifs_notification_btn,
                                        s.getSubredditName()), cancelPi)
                                .build();
                notificationManager.notify((int) (s.getCreated().getTime() / 1000),
                        notification);
            }
        }
    }
    if (Reddit.notificationTime != -1) new NotificationJobScheduler(c).start(c);
}
 
Example 13
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 4 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();

    SpannableStringBuilder title = new SpannableStringBuilder();
    appendStyled(title, "Stylized", new StyleSpan(Typeface.BOLD_ITALIC));
    title.append(" title");
    SpannableStringBuilder text = new SpannableStringBuilder("Stylized text: ");
    appendStyled(text, "C", new ForegroundColorSpan(Color.RED));
    appendStyled(text, "O", new ForegroundColorSpan(Color.GREEN));
    appendStyled(text, "L", new ForegroundColorSpan(Color.BLUE));
    appendStyled(text, "O", new ForegroundColorSpan(Color.YELLOW));
    appendStyled(text, "R", new ForegroundColorSpan(Color.MAGENTA));
    appendStyled(text, "S", new ForegroundColorSpan(Color.CYAN));
    text.append("; ");
    appendStyled(text, "1.25x size", new RelativeSizeSpan(1.25f));
    text.append("; ");
    appendStyled(text, "0.75x size", new RelativeSizeSpan(0.75f));
    text.append("; ");
    appendStyled(text, "underline", new UnderlineSpan());
    text.append("; ");
    appendStyled(text, "strikethrough", new StrikethroughSpan());
    text.append("; ");
    appendStyled(text, "bold", new StyleSpan(Typeface.BOLD));
    text.append("; ");
    appendStyled(text, "italic", new StyleSpan(Typeface.ITALIC));
    text.append("; ");
    appendStyled(text, "sans-serif-thin", new TypefaceSpan("sans-serif-thin"));
    text.append("; ");
    appendStyled(text, "monospace", new TypefaceSpan("monospace"));
    text.append("; ");
    appendStyled(text, "sub", new SubscriptSpan());
    text.append("script");
    appendStyled(text, "super", new SuperscriptSpan());

    style.setBigContentTitle(title);
    style.bigText(text);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setStyle(style);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 14
Source File: ListenerService.java    From sms-ticket with Apache License 2.0 4 votes vote down vote up
private void processNotification(DataMap dataMap) {
    DataMap dataMap1 = dataMap.getDataMap("notification");

    Ticket ticket = new Ticket();

    ticket.setId(dataMap1.getLong("id"));
    ticket.setCityId(dataMap1.getLong("city_id"));
    ticket.setCity(dataMap1.getString("city"));
    ticket.setStatus(dataMap1.getInt("status"));
    ticket.setHash(dataMap1.getString("hash"));
    ticket.setText(dataMap1.getString("text"));
    ticket.setValidFrom(dataMap1.getLong("valid_from"));
    ticket.setValidTo(dataMap1.getLong("valid_to"));
    ticket.setNotificationId(dataMap1.getLong("notification_id"));

    Intent notificationIntent = new Intent(this, NotificationActivity.class);
    notificationIntent.putExtra("ticket", ticket);
    PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
        PendingIntent.FLAG_UPDATE_CURRENT);

    int notificationColor = 0;

    if (ticket.getStatus() == NotificationActivity.STATUS_VALID_EXPIRING) {
        notificationColor = getResources().getColor(R.color.background_city_yellow);
    } else if (ticket.getStatus() == NotificationActivity.STATUS_EXPIRING_EXPIRED) {
        notificationColor = getResources().getColor(R.color.background_city_red);
    } else if (ticket.getStatus() == NotificationActivity.STATUS_EXPIRED) {
        notificationColor = getResources().getColor(R.color.background_city_transparent);
    }

    // Create a big text style for the second page
    NotificationCompat.BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
    secondPageStyle.setBigContentTitle(getResources().getString(R.string.sms))
        .bigText(ticket.getText());

    Notification secondPageNotification =
        new NotificationCompat.Builder(this)
            .setStyle(secondPageStyle)
            .build();

    Intent intent = new Intent(this, OpenPhoneReceiver.class);
    intent.setAction("eu.inmite.apps.smsjizdenka.openphone");
    intent.putExtra("ticket", ticket);
    PendingIntent openPhonePendingIntent = PendingIntent.getBroadcast(this, 0, intent,
        PendingIntent.FLAG_UPDATE_CURRENT);

    int resourceIdForCity = Constants.CITIES_BACKGROUND_MAP.containsKey(ticket.getCityId()) ? Constants
        .CITIES_BACKGROUND_MAP.get(ticket.getCityId()) : 0;
    Notification notification = new Notification.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentText(getStatusTitle(ticket))
        .extend(new Notification.WearableExtender()
            .setDisplayIntent(notificationPendingIntent)
            .setCustomContentHeight(getResources().getDimensionPixelSize(R.dimen.notification_size))
            .setStartScrollBottom(true)
            .setBackground(ImageUtil.combineTwoImages(this, resourceIdForCity, notificationColor))
            .addPage(secondPageNotification)
            .addAction(new Notification.Action(R.drawable.go_to_phone_00156, "Open on phone", openPhonePendingIntent)))
        .build();

    notification.defaults |= Notification.DEFAULT_VIBRATE;

    NotificationManager notificationManager =
        (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify((int)ticket.getNotificationId(), notification);

}
 
Example 15
Source File: NotifyUtil.java    From NotificationDemo with Apache License 2.0 4 votes vote down vote up
public static NotificationCompat.BigTextStyle makeBigText(CharSequence content) {
    return new NotificationCompat.BigTextStyle().bigText(content);
}
 
Example 16
Source File: NotificationsService.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
public void sendNotification(NotificationEvent event, Bitmap avatar) {
    eventsHistory.put(event.notifyId(), event);


    String title = createTitle(event);
    String text = createContent(event);
    String summaryText = createSummary(event);

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(title);
    bigTextStyle.bigText(text);
    bigTextStyle.setSummaryText(summaryText);

    String channelId = getChannelId(event);
    String channelName = getChannelName(event);

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


    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId);

    if (avatar != null && !event.fromSite()) {
        builder.setLargeIcon(avatar);
    }
    builder.setSmallIcon(createSmallIcon(event));

    builder.setContentTitle(title);
    builder.setContentText(text);
    builder.setStyle(bigTextStyle);
    builder.setChannelId(channelId);


    Intent notifyIntent = new Intent(this, MainActivity.class);
    notifyIntent.setData(Uri.parse(createIntentUrl(event)));
    notifyIntent.setAction(Intent.ACTION_VIEW);
    PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);
    builder.setContentIntent(notifyPendingIntent);

    configureNotification(builder);

    mNotificationManager.cancel(event.notifyId());
    mNotificationManager.notify(event.notifyId(), builder.build());
}
 
Example 17
Source File: MapzenNotificationCreator.java    From open with GNU General Public License v3.0 4 votes vote down vote up
private void initBigTextStyle(String title, String content) {
    bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(title);
    bigTextStyle.bigText(content);
}
 
Example 18
Source File: Refresher.java    From AnotherRSS with The Unlicense 4 votes vote down vote up
private void notify(ContentValues cv, PendingIntent pi, Uri sound, boolean isHeadUp) {
    // 4 = no notification
    if (_notifyType == 4) return;

    String body = FeedContract.removeHtml(cv.getAsString(FeedContract.Feeds.COLUMN_Body));
    String title= FeedContract.removeHtml(cv.getAsString(FeedContract.Feeds.COLUMN_Title));
    String link = cv.getAsString(FeedContract.Feeds.COLUMN_Link);
    Bitmap largeIcon = FeedContract.getImage(cv.getAsByteArray(FeedContract.Feeds.COLUMN_Image));

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(_ctx);

    NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
    bigStyle.bigText(body);

    if (largeIcon == null) {
        largeIcon = BitmapFactory.decodeResource(_ctx.getResources(), R.drawable.ic_launcher);
    }

    mBuilder.setContentTitle(title)
            .setContentText(body)
            .setTicker(body)
            .setContentIntent(pi)
            .setStyle(bigStyle)
            .setSmallIcon(R.drawable.logo_sw)
            .setLargeIcon(largeIcon);

    if (! isHeadUp) {
        Intent linkIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
        PendingIntent linkpi = PendingIntent.getActivity(
                AnotherRSS.getContextOfApplication(), 0, linkIntent, 0
        );
        mBuilder.addAction(
                android.R.drawable.ic_menu_view,
                AnotherRSS.getContextOfApplication().getString(R.string.open),
                linkpi
        );
    } else {
        mBuilder.setPriority(Notification.PRIORITY_HIGH);
    }

    if (sound != null) {
        mBuilder.setSound(sound);
    } else {
        if (_pref.getString("notify_sound", AnotherRSS.Config.DEFAULT_notifySound).equals("1")) {
            // default Handy sound
            sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            mBuilder.setSound(sound);
        }
        // no sound
    }

    switch (_notifyType) {
        case 1:
            mBuilder.setLights(_notifyColor, 1000, 0);
            break;
        case 2:
            mBuilder.setLights(_notifyColor, 4000, 1000);
            break;
        case 3:
            mBuilder.setLights(_notifyColor, 500, 200);
            break;
        default:
    }

    Notification noti = mBuilder.build();
    noti.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager mNotifyMgr =
            (NotificationManager) _ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotifyMgr.notify(cv.getAsInteger(FeedContract.Feeds._ID), noti);
}