Java Code Examples for android.support.v4.app.NotificationCompat.Builder#setContentIntent()

The following examples show how to use android.support.v4.app.NotificationCompat.Builder#setContentIntent() . 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: AlarmAlertReceiver.java    From OmniList with GNU Affero General Public License v3.0 4 votes vote down vote up
private void onAlert(Alarm alarm) {
    int alarmCode = (int) alarm.getCode();
    Assignment assignment = AssignmentsStore.getInstance().get(alarm.getModelCode());
    /*If the assignment is null, we don't show notification for it*/
    if (assignment == null) {
        alarmsManager.removeAlarm(alarm);
        return;
    }

    Builder mBuilder = new Builder(context)
            .setContentTitle(assignment.getName())
            .setContentText(assignment.getComment())
            .setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_assignment_turned_in_black_24dp)
            .setColor(ColorUtils.accentColor());

    /*Add action: mark as done.*/
    Intent mdIntent = new Intent(context, AlarmAlertReceiver.class);
    mdIntent.setAction(Constants.ACTION_MARK_ASSIGNMENT_AS_DONE);
    mdIntent.putExtra(Constants.EXTRA_CODE, assignment.getCode());
    mdIntent.putExtra(Constants.EXTRA_NOTIFICATION_ID, (int) alarm.getCode());
    PendingIntent piMD = PendingIntent.getBroadcast(
            context, (int) alarm.getCode(), mdIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    mBuilder.addAction(R.drawable.ic_check_circle_black_24dp, context.getString(R.string.mark_as_done), piMD);

    /*Add action: postpone.*/
    Intent pIntent = new Intent(context, AlarmAlertReceiver.class);
    pIntent.setAction(Constants.ACTION_POSTPONE_ALARM);
    pIntent.putExtra(Constants.EXTRA_CODE, alarm.getCode());
    pIntent.putExtra(Constants.EXTRA_NOTIFICATION_ID, (int) alarm.getCode());
    PendingIntent piP = PendingIntent.getBroadcast(
            context, (int) alarm.getCode(), pIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    int snoozeMinutes = NoticePreferences.getInstance().getSnoozeDuration();
    mBuilder.addAction(R.drawable.ic_snooze_black_24dp, String.format(context.getString(R.string.remind_in_minutes), snoozeMinutes), piP);

    /*Add action: click.*/
    Intent clickIntent = new Intent(context, ContentActivity.class);
    clickIntent.setAction(Constants.ACTION_NOTIFICATION);
    clickIntent.putExtra(Constants.EXTRA_CODE, assignment.getCode());
    clickIntent.putExtra(Constants.EXTRA_FRAGMENT, Constants.VALUE_FRAGMENT_ASSIGNMENT);
    clickIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(
            context, (int) assignment.getCode(), clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(contentIntent);

    /*Vibrate.*/
    if (NoticePreferences.getInstance().isVibrateAllowed()) {
        mBuilder.setVibrate(getVibrate());
    }

    /*Ringtone.*/
    String ringtone = NoticePreferences.getInstance().getNotificationRingtone(); // 铃声
    if (ringtone != null){
        mBuilder.setSound(Uri.parse(ringtone));
    }

    Notification notification = mBuilder.build();

    /*Light.*/
    setNotificationLight(notification);

    notificationManager.notify(alarmCode, notification);
}
 
Example 2
Source File: SipNotifications.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
public synchronized void notifyRegisteredAccounts(ArrayList<SipProfileState> activeAccountsInfos, boolean showNumbers) {
	if (!isServiceWrapper) {
		Log.e(THIS_FILE, "Trying to create a service notification from outside the service");
		return;
	}
	int icon = R.drawable.ic_stat_sipok;
	CharSequence tickerText = context.getString(R.string.service_ticker_registered_text);
	long when = System.currentTimeMillis();
	

       Builder nb = new Builder(context);
       nb.setSmallIcon(icon);
       nb.setTicker(tickerText);
       nb.setWhen(when);
	Intent notificationIntent = new Intent(SipManager.ACTION_SIP_DIALER);
	notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
	
	RegistrationNotification contentView = new RegistrationNotification(context.getPackageName());
	contentView.clearRegistrations();
	if(!Compatibility.isCompatible(9)) {
	    contentView.setTextsColor(notificationPrimaryTextColor);
	}
	contentView.addAccountInfos(context, activeAccountsInfos);

	// notification.setLatestEventInfo(context, contentTitle,
	// contentText, contentIntent);
	nb.setOngoing(true);
	nb.setOnlyAlertOnce(true);
       nb.setContentIntent(contentIntent);
       nb.setContent(contentView);
	
	Notification notification = nb.build();
	notification.flags |= Notification.FLAG_NO_CLEAR;
	// We have to re-write content view because getNotification setLatestEventInfo implicitly
       notification.contentView = contentView;
	if (showNumbers) {
           // This only affects android 2.3 and lower
           notification.number = activeAccountsInfos.size();
       }
	startForegroundCompat(REGISTER_NOTIF_ID, notification);
}
 
Example 3
Source File: IMNotificationManager.java    From sctalk with Apache License 2.0 4 votes vote down vote up
private void showInNotificationBar(String title,String ticker, Bitmap iconBitmap,int notificationId,Intent intent) {
	logger.d("notification#showInNotificationBar title:%s ticker:%s",title,ticker);

	NotificationManager notifyMgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
	if (notifyMgr == null) {
		return;
	}

	Builder builder = new NotificationCompat.Builder(ctx);
	builder.setContentTitle(title);
	builder.setContentText(ticker);
	builder.setSmallIcon(R.drawable.tt_small_icon);
	builder.setTicker(ticker);
	builder.setWhen(System.currentTimeMillis());
	builder.setAutoCancel(true);

	// this is the content near the right bottom side
	// builder.setContentInfo("content info");

	if (configurationSp.getCfg(SysConstant.SETTING_GLOBAL,ConfigurationSp.CfgDimension.VIBRATION)) {
		// delay 0ms, vibrate 200ms, delay 250ms, vibrate 200ms
		long[] vibrate = {0, 200, 250, 200};
		builder.setVibrate(vibrate);
	} else {
		logger.d("notification#setting is not using vibration");
	}

	// sound
	if (configurationSp.getCfg(SysConstant.SETTING_GLOBAL,ConfigurationSp.CfgDimension.SOUND)) {
		builder.setDefaults(Notification.DEFAULT_SOUND);
	} else {
		logger.d("notification#setting is not using sound");
	}
	if (iconBitmap != null) {
		logger.d("notification#fetch icon from network ok");
		builder.setLargeIcon(iconBitmap);
	} else {
           // do nothint ?
	}
	// if MessageActivity is in the background, the system would bring it to
	// the front
	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	PendingIntent pendingIntent = PendingIntent.getActivity(ctx, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
	builder.setContentIntent(pendingIntent);
	Notification notification = builder.build();
	notifyMgr.notify(notificationId, notification);
}
 
Example 4
Source File: FriendRequestService.java    From Klyph with MIT License 4 votes vote down vote up
private void onRequestSuccess(List<GraphObject> list)
{
	Log.d("FriendRequestService", "Num friend request : " + list.size());
	Log.d("FriendRequestService", "Service : " + service.get());
	if (service.get() == null)
		return;

	Service s = service.get();

	if (list.size() > 0)
	{
		FriendRequest fq = (FriendRequest) list.get(0);
		KlyphPreferences.setFriendRequestServiceOffset(fq.getTime());

		final Builder builder = KlyphNotification.getBuilder(s, true);
		builder.setContentTitle(fq.getUid_from_name()).setContentText(
				s.getString(R.string.notification_friendrequest_message, fq.getUid_from_name()));

		if (KlyphPreferences.mustGroupNotifications() && list.size() > 1)
		{
			sendNotification(list);
		}
		else
		{
			boolean isFirst = true;
			for (GraphObject graphObject : list)
			{
				FriendRequest fr = (FriendRequest) graphObject;

				TaskStackBuilder stackBuilder = TaskStackBuilder.create(service.get());
				Intent intent = Klyph.getIntentForGraphObject(service.get(), fr);

				// stackBuilder.addParentStack(UserActivity.class);
				Intent mainIntent = new Intent(service.get(), MainActivity.class);
				mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
									| Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
									| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

				stackBuilder.addNextIntent(mainIntent);
				stackBuilder.addNextIntent(intent);

				int intentCode = (int) Math.round(Math.random() * 1000000);

				// Gets a PendingIntent containing the entire back stack
				PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(intentCode, PendingIntent.FLAG_UPDATE_CURRENT);
				builder.setContentIntent(resultPendingIntent);

				builder.setContentTitle(fr.getUid_from_name());
				builder.setContentText(s.getString(R.string.notification_friendrequest_message, fr.getUid_from_name()));
				builder.setTicker(s.getString(R.string.notification_friendrequest_message, fr.getUid_from_name()));
				
				if (isFirst == false)
				{
					KlyphNotification.setNoSound(builder);
					KlyphNotification.setNoVibration(builder);
				}
				
				KlyphNotification.sendNotification(s, builder);

				isFirst = false;
			}
		}

		service.get().stopSelf();
	}
	else
	{
		s.stopSelf();
	}
}
 
Example 5
Source File: FriendRequestService.java    From Klyph with MIT License 4 votes vote down vote up
private void sendNotification(List<GraphObject> list)
{
	if (service.get() == null)
		return;

	Service s = service.get();

	final Builder builder = KlyphNotification.getBuilder(s, true);

	builder.setContentTitle(s.getString(R.string.app_large_name)).setContentText(s.getString(R.string.new_friend_requests, list.size()))
			.setTicker(s.getString(R.string.new_friend_requests, list.size()));

	// Big notification style
	if (list.size() > 1)
	{
		List<String> lines = new ArrayList<String>();
		for (int i = 0; i < list.size(); i++)
		{
			lines.add(((FriendRequest) list.get(i)).getUid_from_name());
		}

		KlyphNotification.setInboxStyle(builder, s.getString(R.string.new_friend_requests, list.size()), lines);
	}

	TaskStackBuilder stackBuilder = TaskStackBuilder.create(service.get());

	Intent resultIntent = new Intent(service.get(), MainActivity.class);
	resultIntent.putExtra(KlyphBundleExtras.SHOW_NOTIFICATION_MENU, true);
	// stackBuilder.addParentStack(MainActivity.class);

	// Adds the Intent to the top of the stack
	stackBuilder.addNextIntentWithParentStack(resultIntent);

	int intentCode = (int) Math.round(Math.random() * 1000000);

	// Gets a PendingIntent containing the entire back stack
	PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(intentCode, PendingIntent.FLAG_UPDATE_CURRENT);
	builder.setContentIntent(resultPendingIntent);

	if (builder != null)
	{
		KlyphNotification.sendNotification(s, builder);
	}
}
 
Example 6
Source File: KlyphNotification.java    From Klyph with MIT License 3 votes vote down vote up
public static void sendNotification(Context context, Builder builder)
{
	TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

	Intent resultIntent = new Intent(context, MainActivity.class);
	resultIntent.putExtra(KlyphBundleExtras.SHOW_NOTIFICATION_MENU, true);

	stackBuilder.addNextIntentWithParentStack(resultIntent);

	int intentCode = (int) Math.round(Math.random() * 1000000);

	// Gets a PendingIntent containing the entire back stack
	PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(intentCode, PendingIntent.FLAG_UPDATE_CURRENT);
	builder.setContentIntent(resultPendingIntent);
	
	Intent intent = new Intent(context, NotificationGroupDeletedReceiver.class);
	builder.setDeleteIntent(PendingIntent.getBroadcast(context.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));

	final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

	final String tag = context.getPackageName() + "_grouped";
	final int id = 0;

	// pair (tag, id) must be unique
	// tag is the unique key
	mNotificationManager.notify(tag, id, builder.build());

}