<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Anroid Notification Backwards Compatibility &#8211; CS@Worcester</title>
	<atom:link href="https://cs.worcester.edu/category/anroid-notification-backwards-compatibility/feed/" rel="self" type="application/rss+xml" />
	<link>https://cs.worcester.edu</link>
	<description>Worcester State University Computer Science Department</description>
	<lastBuildDate>Mon, 26 Nov 2012 22:46:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
<site xmlns="com-wordpress:feed-additions:1">236835116</site>	<item>
		<title>JellyBean Notification with Backwards Compatibility</title>
		<link>http://dhimitraq.wordpress.com/2012/11/26/jellybean-notification-with-backwards-compatability/</link>
		
		<dc:creator><![CDATA[dhimitraq]]></dc:creator>
		<pubDate>Mon, 26 Nov 2012 22:46:12 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Android Notification]]></category>
		<category><![CDATA[Android NotificationCompat]]></category>
		<category><![CDATA[Anroid Notification Backwards Compatibility]]></category>
		<category><![CDATA[WSU CS]]></category>
		<guid isPermaLink="false">http://dhimitraq.wordpress.com/?p=55</guid>

					<description><![CDATA[Using NotificationCompa from android.support.v4.app allows for backwards compatibility when creating notifications for your Android app. Bellow is a class that defines two basic methods for the notifications, however at this point it should be easy to go trough the documentation, and call the extra methods to set more things&#8211;even using the new android Jelly Bean [&#8230;]<img alt="" border="0" src="http://pixel.wp.com/b.gif?host=dhimitraq.wordpress.com&#38;blog=31909135&#38;post=55&#38;subd=dhimitraq&#38;ref=&#38;feed=1" width="1" height="1">]]></description>
										<content:encoded><![CDATA[<p>Using NotificationCompa from android.support.v4.app allows for backwards compatibility when creating notifications for your Android app. Bellow is a class that defines two basic methods for the notifications, however at this point it should be easy to go trough <a href="http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html" title="NotificationCompat.Builder" >the documentation</a>, and call the extra methods to set more things&#8211;even using the new android Jelly Bean notification goodies&#8211; for example the second method creates a persistent notification by setting onGoing flag true. </p>
<p>Speaking of flags:</p>
<pre class="brush: java; title: ; notranslate">
//you can NOT set flags directly like
notification.flags |= Notification.FLAG_AUTO_CANCEL;
//you have to use the methods in NotificationCompat.Builder
builder.setAutoCancel(true); </pre>
<p>Things of note in the code is that in <em>Notification notification = builder.getNotification();</em> notification is still a <em>Notification</em> object and not a <em>NotificationCompat</em> object, however the builder was defined as a <em>NotificationCompat.Builder</em>, this is helpful because the <em>NotificationManager.notify()</em> only accepts Notification objects.</p>
<pre class="brush: java; title: ; notranslate">
package edu.worcester.cs499summer2012.service;

import edu.worcester.cs499summer2012.R;
import edu.worcester.cs499summer2012.activity.ViewTaskActivity;
import edu.worcester.cs499summer2012.task.Task;

import android.app.Notification;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

/**
 * Creates Notifications using NotificationCompat to allow for
 * comparability though different API levels
 * 
 * @author Dhimitraq Jorgji
 *
 */
public class NotificationHelper{
	/**
	 * Basic Text Notification for Task Butler, using NotificationCompat
	 * @param context 
	 * @param id id of task, call task.getID() and pass it to this parameter
	 */
	public void sendBasicNotification(Context context, Task task) {
		NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
			.setContentText(task.getName())
			.setContentTitle(context.getText(R.string.app_name))
			.setSmallIcon(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB ? 
					R.drawable.ic_notification : R.drawable.ic_notification_deprecated)
			.setAutoCancel(true)
			.setContentIntent(getPendingIntent(context, task.getID()))
			.setWhen(System.currentTimeMillis())
			.setDefaults(Notification.DEFAULT_ALL);
		Notification notification = builder.getNotification();
		NotificationManager notificationManager = getNotificationManager(context);
		notificationManager.notify(task.getID(), notification);
	}
	/**
	 * Basic Text Notification with Ongoing flag enabled for Task Butler, using NotificationCompat
	 * @param context 
	 * @param id id of task, call task.getID() and pass it to this parameter
	 */
	public void sendPersistentNotification(Context context, Task task) {
		NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
			.setContentText(task.getName())
			.setContentTitle(context.getText(R.string.app_name))
			.setSmallIcon(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB ? 
					R.drawable.ic_notification : R.drawable.ic_notification_deprecated)
			.setAutoCancel(true)
			.setContentIntent(getPendingIntent(context,task.getID()))
			.setWhen(System.currentTimeMillis())
			.setOngoing(true)
			.setDefaults(Notification.DEFAULT_ALL);
		Notification notification = builder.getNotification();
		NotificationManager notificationManager = getNotificationManager(context);
		notificationManager.notify(task.getID(), notification);
	}
	//get a PendingIntent
	PendingIntent getPendingIntent(Context context, int id) {
		Intent intent =  new Intent(context, ViewTaskActivity.class)
			.putExtra(Task.EXTRA_TASK_ID, id);
		return PendingIntent.getActivity(context, id, intent, 0);
	}
	//get a NotificationManager
	NotificationManager getNotificationManager(Context context) {
		return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
	}
}
</pre>
<p>All of the source code for Task Butler can be found on <a href="https://github.com/CS-Worcester/CS499Summer2012" title="Source Code on GitHub" >GitHub</a>, including the above code.</p>
<p>Any questions shoot away in the comments bellow.</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dhimitraq.wordpress.com/55/"><img decoding="async" alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dhimitraq.wordpress.com/55/" /></a> <img data-recalc-dims="1" decoding="async" alt="" border="0" src="https://i0.wp.com/pixel.wp.com/b.gif?resize=1%2C1" width="1" height="1" /></p>

<p class="syndicated-attribution"><em>From the blog <a href="http://dhimitraq.wordpress.com">Live and Code » WSU CS</a> by <a href="https://cs.worcester.edu/author/0/" title="Read other posts by dhimitraq">dhimitraq</a></em> and used with permission of the author. All other rights reserved by the author.</p>]]></content:encoded>
					
		
		<enclosure url="http://2.gravatar.com/avatar/520270a1b47b277b8ee7fb185decef7b?s=96&#038;d=identicon&#038;r=G" length="0" type="" />

		<post-id xmlns="com-wordpress:feed-additions:1">1236</post-id>	</item>
	</channel>
</rss>
