android.support.v4.app.NotificationCompat.Builder Java Examples

The following examples show how to use android.support.v4.app.NotificationCompat.Builder. 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: GCMUtils.java    From buddycloud-android with Apache License 2.0 6 votes vote down vote up
public static Notification build(Context context,
		NotificationCompat.Builder mBuilder, Intent resultIntent) {
	TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
	stackBuilder.addParentStack(MainActivity.class);
	stackBuilder.addNextIntent(resultIntent);
	PendingIntent resultPendingIntent =
	        stackBuilder.getPendingIntent(
	            0,
	            PendingIntent.FLAG_UPDATE_CURRENT
	        );
	mBuilder.setContentIntent(resultPendingIntent);
	
	Notification notification = mBuilder.build();
	notification.flags |= Notification.FLAG_AUTO_CANCEL;
	notification.flags |= Notification.FLAG_SHOW_LIGHTS;
	return notification;
}
 
Example #2
Source File: NotificationService.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
private Person getPerson(Message message) {
    final Contact contact = message.getContact();
    final Person.Builder builder = new Person.Builder();
    if (contact != null) {
        builder.setName(contact.getDisplayName());
        final Uri uri = contact.getSystemAccount();
        if (uri != null) {
            builder.setUri(uri.toString());
        }
    } else {
        builder.setName(UIHelper.getMessageDisplayName(message));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        builder.setIcon(IconCompat.createWithBitmap(mXmppConnectionService.getAvatarService().get(message, AvatarService.getSystemUiAvatarSize(mXmppConnectionService), false)));
    }
    return builder.build();
}
 
Example #3
Source File: NotificationBuilder.java    From beaconloc with Apache License 2.0 6 votes vote down vote up
public NotificationBuilder setRingtone(String ringtone) {
    // Ringtone options
    if (ringtone != null && ringtone.length() > 0) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            AudioAttributes att = new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .build();
            //mNotificationChannel.setSound(Uri.parse(ringtone), att);

            // if not a silent sound, play
            if (!ringtone.equals(mContext.getString(R.string.pref_bn_none_notification_action_ringtone))) {
                Ringtone r = RingtoneManager.getRingtone(mContext.getApplicationContext(), Uri.parse(ringtone));
                try {
                    r.play();
                } catch (Exception e) {

                }
            }
        } else {
            mBuilder.setSound(Uri.parse(ringtone), AudioManager.STREAM_NOTIFICATION);
        }
    }

    return this;
}
 
Example #4
Source File: UploadVideoService.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the Notification to show the progress of video upload.
 */
private void startNotification() {
    // Gets access to the Android Notification Service.
    mNotifyManager = (NotificationManager)
        getSystemService(Context.NOTIFICATION_SERVICE); 

    // Create the Notification and set a progress indicator for an
    // operation of indeterminate length.
    mBuilder = new NotificationCompat
                   .Builder(this)
                   .setContentTitle("Video Upload") 
                   .setContentText("Upload in progress") 
                   .setSmallIcon(android.R.drawable.stat_sys_upload)
                   .setTicker("Uploading video")
                   .setProgress(0,
                                0,
                                true);
 
    // Build and issue the notification.
    mNotifyManager.notify(NOTIFICATION_ID,
                          mBuilder.build());
}
 
Example #5
Source File: UploadVideoService.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the Notification to show the progress of video upload.
 */
private void startNotification() {
    // Gets access to the Android Notification Service.
    mNotifyManager = (NotificationManager)
        getSystemService(Context.NOTIFICATION_SERVICE); 

    // Create the Notification and set a progress indicator for an
    // operation of indeterminate length.
    mBuilder = new NotificationCompat
                   .Builder(this)
                   .setContentTitle("Video Upload") 
                   .setContentText("Upload in progress") 
                   .setSmallIcon(android.R.drawable.stat_sys_upload)
                   .setTicker("Uploading video")
                   .setProgress(0,
                                0,
                                true);
 
    // Build and issue the notification.
    mNotifyManager.notify(NOTIFICATION_ID,
                          mBuilder.build());
}
 
Example #6
Source File: WearMessageHandlerService.java    From android-wear-gopro-remote with Apache License 2.0 6 votes vote down vote up
void updateNotification(String contentText) {
    if(mNotificationBuilder == null) {
        Context context = getApplicationContext();
        Intent activityIntent = new Intent(context, MobileMainActivity.class);
        activityIntent.setAction(Intent.ACTION_MAIN);
        activityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        activityIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NEW_TASK);

        Intent stopIntent = new Intent(context, WearMessageHandlerService.class);
        stopIntent.setAction(ACTION_STOP);

        mNotificationBuilder = (new Builder(this))
                .setSmallIcon(R.drawable.icon_notification)
                .setContentTitle(getString(R.string.notification_tittle))
                .setContentIntent(PendingIntent.getActivity(context, 0, activityIntent, 0))
                .setLocalOnly(true)
                .addAction(R.drawable.icon_power, getString(R.string.action_stop),
                        PendingIntent.getService(context, 0, stopIntent, 0));
    }

    mNotificationBuilder.setContentText(contentText);
    startForeground(1, mNotificationBuilder.build());
}
 
Example #7
Source File: ContactSync.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
private void backupFound(){
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    if(jbBackupM.toString().trim().length()>0){
        Intent dialogIntent = new Intent(this, AddToContactList.class);
        dialogIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        dialogIntent.putExtra("data", jbBackupM.toString());
        PendingIntent intent = PendingIntent.getActivity(this, 0, dialogIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(intent);
    }
    mBuilder.setSmallIcon(R.drawable.ic_custom_notification);
    mBuilder.setAutoCancel(true);
    mBuilder.setContentTitle("Contact Sync!!");
    mBuilder.setContentText("You have lost some contact, we have backup");
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // notificationID allows you to update the notification later on.
    mNotificationManager.notify(notificaitonId, mBuilder.build());
}
 
Example #8
Source File: NotificationService.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
public Notification getOngoingCallNotification(final AbstractJingleConnection.Id id, final Set<Media> media) {
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(mXmppConnectionService, "ongoing_calls");
    if (media.contains(Media.VIDEO)) {
        builder.setSmallIcon(R.drawable.ic_videocam_white_24dp);
        builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_video_call));
    } else {
        builder.setSmallIcon(R.drawable.ic_call_white_24dp);
        builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_call));
    }
    builder.setContentText(id.account.getRoster().getContact(id.with).getDisplayName());
    builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    builder.setPriority(NotificationCompat.PRIORITY_HIGH);
    builder.setCategory(NotificationCompat.CATEGORY_CALL);
    builder.setContentIntent(createPendingRtpSession(id, Intent.ACTION_VIEW, 101));
    builder.setOngoing(true);
    builder.addAction(new NotificationCompat.Action.Builder(
            R.drawable.ic_call_end_white_48dp,
            mXmppConnectionService.getString(R.string.hang_up),
            createCallAction(id.sessionId, XmppConnectionService.ACTION_END_CALL, 104))
            .build());
    return builder.build();
}
 
Example #9
Source File: ContactSync.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
private void backupFound(){
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    if(jbBackupM.toString().trim().length()>0){
        Intent dialogIntent = new Intent(this, AddToContactList.class);
        dialogIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        dialogIntent.putExtra("data", jbBackupM.toString());
        PendingIntent intent = PendingIntent.getActivity(this, 0, dialogIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(intent);
    }
    mBuilder.setSmallIcon(R.drawable.ic_custom_notification);
    mBuilder.setAutoCancel(true);
    mBuilder.setContentTitle("Contact Sync!!");
    mBuilder.setContentText("You have lost some contact, we have backup");
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // notificationID allows you to update the notification later on.
    mNotificationManager.notify(notificaitonId, mBuilder.build());
}
 
Example #10
Source File: GCMUtils.java    From buddycloud-android with Apache License 2.0 6 votes vote down vote up
public static Builder createNotificationBuilder(Context context) {
	NotificationCompat.Builder builder =
	        new NotificationCompat.Builder(context)
	        .setSmallIcon(R.drawable.ic_notification)
	        .setLights(context.getResources().getColor(R.color.bc_green_blue_color), 1000, 1000);
	
	SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
	
	boolean doVibrate = sharedPrefs.getBoolean("pref_key_enable_vibration", true);
	if (doVibrate) {
		builder.setVibrate(new long[] {500, 500, 500});
	}
	
	boolean playAudio = sharedPrefs.getBoolean("pref_key_enable_sound", true);
	if (playAudio) {
		Uri soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.cp);
		builder.setSound(soundUri);
	}
	
	setPriority(builder);
	builder.setDeleteIntent(getDeleteIntent(context));
	
	return builder;
}
 
Example #11
Source File: NotificationService.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private void modifyForSoundVibrationAndLight(Builder mBuilder, boolean notify, boolean quietHours, SharedPreferences preferences) {
    final Resources resources = mXmppConnectionService.getResources();
    final String ringtone = preferences.getString("notification_ringtone", resources.getString(R.string.notification_ringtone));
    final boolean vibrate = preferences.getBoolean("vibrate_on_notification", resources.getBoolean(R.bool.vibrate_on_notification));
    final boolean led = preferences.getBoolean("led", resources.getBoolean(R.bool.led));
    final boolean headsup = preferences.getBoolean("notification_headsup", resources.getBoolean(R.bool.headsup_notifications));
    if (notify && !quietHours) {
        if (vibrate) {
            final int dat = 70;
            final long[] pattern = {0, 3 * dat, dat, dat};
            mBuilder.setVibrate(pattern);
        } else {
            mBuilder.setVibrate(new long[]{0});
        }
        Uri uri = Uri.parse(ringtone);
        try {
            mBuilder.setSound(fixRingtoneUri(uri));
        } catch (SecurityException e) {
            Log.d(Config.LOGTAG, "unable to use custom notification sound " + uri.toString());
        }
    } else {
        mBuilder.setLocalOnly(true);
    }
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setCategory(Notification.CATEGORY_MESSAGE);
    }
    mBuilder.setPriority(notify ? (headsup ? NotificationCompat.PRIORITY_HIGH : NotificationCompat.PRIORITY_DEFAULT) : NotificationCompat.PRIORITY_LOW);
    setNotificationColor(mBuilder);
    mBuilder.setDefaults(0);
    if (led) {
        mBuilder.setLights(LED_COLOR, 2000, 3000);
    }
}
 
Example #12
Source File: IRCService.java    From Atomic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handle command
 *
 * @param intent
 */
private void handleCommand(Intent intent) {
  if( ACTION_FOREGROUND.equals(intent.getAction()) ) {
    if( foreground ) {
      return; // XXX: We are already in foreground...
    }
    foreground = true;


    Intent notifyIntent = new Intent(this, ServersActivity.class);
    notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);


    // Set the icon, scrolling text and timestamp
    // now using NotificationCompat for Linter happiness
    Notification notification = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_service_icon)
        .setWhen(System.currentTimeMillis())
        .setContentText(getText(R.string.notification_running))
        .setTicker(getText(R.string.notification_not_connected))
        .setContentTitle(getText(R.string.app_name))
        .setContentIntent(contentIntent)
        .setPriority(Notification.PRIORITY_MIN)
        .build();

    startForegroundCompat(FOREGROUND_NOTIFICATION, notification);
  } else if( ACTION_BACKGROUND.equals(intent.getAction()) && !foreground ) {
    stopForegroundCompat(FOREGROUND_NOTIFICATION);
  } else if( ACTION_ACK_NEW_MENTIONS.equals(intent.getAction()) ) {
    ackNewMentions(intent.getIntExtra(EXTRA_ACK_SERVERID, -1), intent.getStringExtra(EXTRA_ACK_CONVTITLE));
  }
}
 
Example #13
Source File: ChatNotificationHelper.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
private ChatNotificationHelper(Context context) {
    //Private Constructor
    this();
    mNotificationBuilder = new Builder(context);
    mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationSoundUri = getUserSelectedSoundUri();
    mNotificationsEnabled = getNotificationsEnabled();
    mVibrationEnabled = getVibrationEnabled();

}
 
Example #14
Source File: AlarmAlertReceiver.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
private void onSnoozed(Alarm alarm) {
    LogUtils.d("onSnoozed: " + alarm);
    int alarmCode = (int) alarm.getCode();
    Assignment assignment = AssignmentsStore.getInstance().get(alarm.getModelCode());

    /*Add action cancel.*/
    Intent cancelIntent = new Intent(context, AlarmAlertReceiver.class);
    cancelIntent.setAction(Constants.ACTION_CANCEL_NOTIFICATION);
    cancelIntent.putExtra(Constants.EXTRA_CODE, alarmCode);
    PendingIntent piCancel = PendingIntent.getBroadcast(context, alarmCode, cancelIntent, 0);

    /*Action dismiss.*/
    PendingIntent piDismiss = PresentationToModelIntents.createPendingIntent(
            context, PresentationToModelIntents.ACTION_REQUEST_DISMISS, alarmCode);

    Notification status = new Builder(context)
            .setContentTitle(assignment.getName())
            .setContentText(assignment.getComment())
            .setSmallIcon(R.drawable.ic_assignment_turned_in_black_24dp)
            .setContentIntent(piCancel)
            .setOngoing(true)
            .addAction(R.drawable.ic_highlight_off_black_24dp, PalmApp.getStringCompact(R.string.text_dismiss), piDismiss)
            .setDefaults(Notification.DEFAULT_LIGHTS)
            .build();

    notificationManager.notify(alarmCode, status);
}
 
Example #15
Source File: NotificationService.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private void modifyIncomingCall(Builder mBuilder) {
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService);
    final Resources resources = mXmppConnectionService.getResources();
    final String ringtone = preferences.getString("call_ringtone", resources.getString(R.string.incoming_call_ringtone));
    mBuilder.setVibrate(CALL_PATTERN);
    final Uri uri = Uri.parse(ringtone);
    try {
        mBuilder.setSound(fixRingtoneUri(uri));
    } catch (SecurityException e) {
        Log.d(Config.LOGTAG, "unable to use custom notification sound " + uri.toString());
    }
    mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
    setNotificationColor(mBuilder);
    mBuilder.setLights(LED_COLOR, 2000, 3000);
}
 
Example #16
Source File: NotificationService.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private void modifyForImage(final Builder builder, final Message message, final ArrayList<Message> messages) {
    try {
        final Bitmap bitmap = mXmppConnectionService.getFileBackend().getThumbnail(message, getPixel(288), false);
        final ArrayList<Message> tmp = new ArrayList<>();
        for (final Message msg : messages) {
            if (msg.getType() == Message.TYPE_TEXT
                    && msg.getTransferable() == null) {
                tmp.add(msg);
            }
        }
        final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
        bigPictureStyle.bigPicture(bitmap);
        if (tmp.size() > 0) {
            CharSequence text = getMergedBodies(tmp);
            bigPictureStyle.setSummaryText(text);
            builder.setContentText(text);
            builder.setTicker(text);
        } else {
            final String description = UIHelper.getFileDescriptionString(mXmppConnectionService, message);
            builder.setContentText(description);
            builder.setTicker(description);
        }
        builder.setStyle(bigPictureStyle);
    } catch (final IOException e) {
        modifyForTextOnly(builder, messages);
    }
}
 
Example #17
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 #18
Source File: NotificationService.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
Notification createForegroundNotification() {
    final Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService);
    mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.app_name));
    final List<Account> accounts = mXmppConnectionService.getAccounts();
    int enabled = 0;
    int connected = 0;
    if (accounts != null) {
        for (Account account : accounts) {
            if (account.isOnlineAndConnected()) {
                connected++;
                enabled++;
            } else if (account.isEnabled()) {
                enabled++;
            }
        }
    }
    mBuilder.setContentText(mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
    final PendingIntent openIntent = createOpenConversationsIntent();
    if (openIntent != null) {
        mBuilder.setContentIntent(openIntent);
    }
    mBuilder.setWhen(0);
    mBuilder.setPriority(Notification.PRIORITY_MIN);
    mBuilder.setSmallIcon(connected > 0 ? R.drawable.ic_link_white_24dp : R.drawable.ic_link_off_white_24dp);

    if (Compatibility.runsTwentySix()) {
        mBuilder.setChannelId("foreground");
    }


    return mBuilder.build();
}
 
Example #19
Source File: NotificationService.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
void updateFileAddingNotification(int current, Message message) {
    Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService);
    mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.transcoding_video));
    mBuilder.setProgress(100, current, false);
    mBuilder.setSmallIcon(R.drawable.ic_hourglass_empty_white_24dp);
    mBuilder.setContentIntent(createContentIntent(message.getConversation()));
    mBuilder.setOngoing(true);
    if (Compatibility.runsTwentySix()) {
        mBuilder.setChannelId("compression");
    }
    Notification notification = mBuilder.build();
    notify(FOREGROUND_NOTIFICATION_ID, notification);
}
 
Example #20
Source File: KlyphMessengerNotification.java    From KlyphMessenger with MIT License 5 votes vote down vote up
public static Builder getBuilder(Context context, boolean alert)
{
	Builder builder = new Builder(context).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setOnlyAlertOnce(!alert);

	int defaults = 0;
	
	if (alert == true)
	{
		if (MessengerPreferences.getNotificationRingtone() != null && MessengerPreferences.getNotificationRingtone().equals("default"))
		{
			defaults |= android.app.Notification.DEFAULT_SOUND;
		}
		else if (MessengerPreferences.getNotificationRingtoneUri() == null)
		{
			builder.setSound(null);
		}
		else
		{
			builder.setSound(Uri.parse(MessengerPreferences.getNotificationRingtoneUri()));
		}

		if (MessengerPreferences.isNotificationVibrationEnabled() == true)
			defaults |= android.app.Notification.DEFAULT_VIBRATE;

		defaults |= android.app.Notification.DEFAULT_LIGHTS;
		
		builder.setDefaults(defaults);
	}
	
	//int defaults = android.app.Notification.DEFAULT_SOUND | android.app.Notification.DEFAULT_VIBRATE;
	builder.setDefaults(defaults);

	return builder;
}
 
Example #21
Source File: KlyphMessengerNotification.java    From KlyphMessenger with MIT License 5 votes vote down vote up
public static void setInboxStyle(Builder builder, String title, List<String> lines)
{
	builder.setNumber(lines.size());
	InboxStyle inboxStyle = new InboxStyle();

	inboxStyle.setBigContentTitle(title);

	for (String line : lines)
	{
		inboxStyle.addLine(line);
	}

	builder.setStyle(inboxStyle);
}
 
Example #22
Source File: KlyphMessengerNotification.java    From KlyphMessenger with MIT License 5 votes vote down vote up
public static void sendNotification(Context context, Builder builder)
{
	final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

	final String tag = AttrUtil.getString(context, R.string.app_name);
	final int id = 0;

	// pair (tag, id) must be unique
	// because n.getObject_id() may not be converted to an int
	// tag is the unique key
	mNotificationManager.notify(tag, id, builder.build());

}
 
Example #23
Source File: WearMessageHandlerService.java    From android-wear-gopro-remote with Apache License 2.0 5 votes vote down vote up
private boolean connectGoogleApiClient() {
    if(mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .build();
    }

    if(!mGoogleApiClient.isConnected() || !mGoogleApiClient.isConnecting()) {
        mGoogleApiClient.blockingConnect();
    }

    return mGoogleApiClient.isConnected();
}
 
Example #24
Source File: NotificationHelper.java    From moVirt with Apache License 2.0 5 votes vote down vote up
private Builder prepareNotification(Context context, PendingIntent resultPendingIntent, long when, String title) {
    return new NotificationCompat.Builder(context)
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setWhen(when)
            .setSmallIcon(org.ovirt.mobile.movirt.R.drawable.ic_launcher)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent);
}
 
Example #25
Source File: Notifications.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private static void updateColumn (final Context context, final DbInterface db, final Set<Integer> columnsHidingRetweets, final Column col, final NotificationManager nm) {
	final int nId = idForColumn(col);
	final int count = db.getUnreadCount(col, columnsHidingRetweets);
	if (count > 0) {
		final Intent showMainActI = new Intent(context, MainActivity.class)
				.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
				.putExtra(MainActivity.ARG_FOCUS_COLUMN_ID, col.getId());
		final PendingIntent showMainActPi = PendingIntent.getActivity(context, col.getId(), showMainActI, PendingIntent.FLAG_CANCEL_CURRENT);

		final List<Tweet> tweets = db.getTweets(col.getId(), Math.min(count, 5),
				Selection.FILTERED, col.getExcludeColumnIds(), columnsHidingRetweets,
				col.getInlineMediaStyle() == InlineMediaStyle.SEAMLESS,
				col.getNotificationStyle().isExcludeRetweets(),
				!col.getNotificationStyle().isIncludeOwnTweets());

		final String msg = makeMsg(col, tweets, count);
		final Style style = makePreview(tweets, count);
		final PendingIntent markAsReadPi = MarkAsReadReceiver.makePi(context, col, tweets);

		final Builder nb = new NotificationCompat.Builder(context)
				.setOnlyAlertOnce(true)
				.setSmallIcon(notificationIcon())
				.setContentTitle(col.getTitle())
				.setContentText(msg)
				.setTicker(msg)
				.setNumber(count)
				.setContentIntent(showMainActPi)
				.setAutoCancel(true)
				.setWhen(System.currentTimeMillis())
				.setStyle(style);
		if (markAsReadPi != null) nb.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Mark as read", markAsReadPi); //ES
		applyStyle(nb, col.getNotificationStyle());
		nm.notify(nId, nb.build());
	}
	else {
		nm.cancel(nId);
	}
}
 
Example #26
Source File: Notifications.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private static void applyStyle (final Builder nb, final NotificationStyle ns) {
	int defaults = 0;
	if (ns.isLights()) defaults |= Notification.DEFAULT_LIGHTS;
	if (ns.isVibrate()) defaults |= Notification.DEFAULT_VIBRATE;
	if (ns.isSound()) defaults |= Notification.DEFAULT_SOUND;
	nb.setDefaults(defaults);
}
 
Example #27
Source File: BatteryNotify.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private static void showNotification (final Context context) {
	final Builder nb = new NotificationCompat.Builder(context)
			.setOnlyAlertOnce(true)
			.setSmallIcon(R.drawable.exclamation_red) // TODO better icon.
			.setContentTitle(context.getString(R.string.background_updating_disabled_notification_title))
			.setContentText(context.getString(R.string.background_updating_disabled_notification_msg))
			.setTicker(context.getString(R.string.background_updating_disabled_notification_title))
			.setAutoCancel(true)
			.setWhen(System.currentTimeMillis())
			.setContentIntent(makeShowMainActPi(context))
			.addAction(android.R.drawable.ic_menu_add,
					String.format("+%s Hour", OVERRIDE_DURATION_HOURS), //ES
					makePlusTimePi(context));
	getManager(context).notify(NOT_UPDATING_NOTIFICATION_ID, nb.build());
}
 
Example #28
Source File: Notify.java    From Sparkplug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Displays a notification in the notification area of the UI
 * @param context Context from which to create the notification
 * @param messageString The string to display to the user as a message
 * @param intent The intent which will start the activity when the user clicks the notification
 * @param notificationTitle The resource reference to the notification title
 */
static void notifcation(Context context, String messageString, Intent intent, int notificationTitle) {

  //Get the notification manage which we will use to display the notification
  String ns = Context.NOTIFICATION_SERVICE;
  NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

  long when = System.currentTimeMillis();

  //get the notification title from the application's strings.xml file
  CharSequence contentTitle = context.getString(notificationTitle);

  //the message that will be displayed as the ticker
  String ticker = contentTitle + " " + messageString;

  //build the pending intent that will start the appropriate activity
  PendingIntent pendingIntent = PendingIntent.getActivity(context,
          0, intent, 0);

  //build the notification
  Builder notificationCompat = new Builder(context);
  notificationCompat.setAutoCancel(true)
      .setContentTitle(contentTitle)
      .setContentIntent(pendingIntent)
      .setContentText(messageString)
      .setTicker(ticker)
      .setWhen(when)
      .setSmallIcon(R.mipmap.ic_launcher);

  Notification notification = notificationCompat.build();
  //display the notification
  mNotificationManager.notify(MessageID, notification);
  MessageID++;

}
 
Example #29
Source File: NotificationsHelper.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public NotificationsHelper createNotification(int smallIcon, String title, PendingIntent notifyIntent) {
    mBuilder = new NotificationCompat.Builder(mContext).setSmallIcon(smallIcon).setContentTitle(title)
            .setAutoCancel(true).setColor(mContext.getResources().getColor(R.color.colorAccent));
    mBuilder.setContentIntent(notifyIntent);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setLargeIcon(R.mipmap.ic_launcher_round);
    } else {
        setLargeIcon(R.mipmap.ic_launcher_round);
    }
    return this;
}
 
Example #30
Source File: StandOutWindow.java    From LogcatViewer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return a persistent {@link Notification} for the corresponding id. You
 * must return a notification for AT LEAST the first id to be requested.
 * Once the persistent notification is shown, further calls to
 * {@link #getPersistentNotification(int)} may return null. This way Android
 * can start the StandOut window service in the foreground and will not kill
 * the service on low memory.
 * 
 * <p>
 * As a courtesy, the system will request a notification for every new id
 * shown. Your implementation is encouraged to include the
 * {@link PendingIntent#FLAG_UPDATE_CURRENT} flag in the notification so
 * that there is only one system-wide persistent notification.
 * 
 * <p>
 * See the StandOutExample project for an implementation of
 * {@link #getPersistentNotification(int)} that keeps one system-wide
 * persistent notification that creates a new window on every click.
 * 
 * @param id
 *            The id of the window.
 * @return The {@link Notification} corresponding to the id, or null if
 *         you've previously returned a notification.
 */
public Notification getPersistentNotification(int id) {
	// basic notification stuff
	// http://developer.android.com/guide/topics/ui/notifiers/notifications.html
	int icon = getAppIcon();
	long when = System.currentTimeMillis();
	Context c = getApplicationContext();
	String contentTitle = getPersistentNotificationTitle(id);
	String tickerText = getPersistentNotificationMessage(id);

	// getPersistentNotification() is called for every new window
	// so we replace the old notification with a new one that has
	// a bigger id
	Intent notificationIntent = getPersistentNotificationIntent(id);

	PendingIntent contentIntent = null;

	if (notificationIntent != null) {
		contentIntent = PendingIntent.getService(this, 0,
				notificationIntent,
				// flag updates existing persistent notification
				PendingIntent.FLAG_UPDATE_CURRENT);
	}

	NotificationCompat.Builder builder = new NotificationCompat.Builder(c);
	builder.setContentTitle(contentTitle);
	builder.setContentText(tickerText);
	builder.setContentIntent(contentIntent);
	builder.setSmallIcon(icon);
	builder.setWhen(when);
	return builder.build();
}