Updated notifications to use the compat notification builder

closes #124
This commit is contained in:
2012-07-16 13:44:16 -04:00
parent 9ec67079c0
commit 507d7901bf
5 changed files with 23 additions and 35 deletions

View File

@@ -9,4 +9,4 @@
android.library=true android.library=true
# Project target. # Project target.
target=android-15 target=android-16

View File

@@ -14,7 +14,6 @@ import java.util.Date;
import java.util.Properties; import java.util.Properties;
import android.app.Activity; import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
@@ -27,6 +26,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Build; import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
/** /**
@@ -120,16 +120,20 @@ public class ExceptionHandler implements UncaughtExceptionHandler, Runnable {
* displays an notification in the status bar, letting the user know that there was an issue * displays an notification in the status bar, letting the user know that there was an issue
* @param generatedReportIntent * @param generatedReportIntent
*/ */
@SuppressWarnings("deprecation")
private void displayNotification(final Intent generatedReportIntent) { private void displayNotification(final Intent generatedReportIntent) {
Log.i(TAG, "displayNotification"); Log.i(TAG, "displayNotification");
final Context context = mContext.getApplicationContext(); final Context context = mContext.getApplicationContext();
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(android.R.drawable.stat_notify_error, context.getString(R.string.sorry), System.currentTimeMillis());
final PendingIntent intent = PendingIntent.getActivity(context, 0, generatedReportIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK); final PendingIntent intent = PendingIntent.getActivity(context, 0, generatedReportIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, context.getString(R.string.crash), context.getString(R.string.sorry), intent); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL; .setContentTitle(context.getString(R.string.crash))
notificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); .setContentText(context.getString(R.string.sorry))
.setTicker(context.getString(R.string.crash))
.setSmallIcon(android.R.drawable.stat_notify_error)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentIntent(intent);
notificationManager.notify(SIMPLE_NOTFICATION_ID, builder.getNotification());
} }
/** /**

View File

@@ -10,16 +10,14 @@ import java.io.IOException;
import org.apache.http.client.ClientProtocolException; import org.apache.http.client.ClientProtocolException;
import android.annotation.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.IBinder; import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
/** /**
@@ -48,38 +46,26 @@ public class ReportPostingService extends Service {
* @param isOngoing * @param isOngoing
* @author ricky barrette * @author ricky barrette
*/ */
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
private void fireNotification(final String title, final String contentText, final String ticker, final int icon, final Intent intent, final boolean isOngoing) { private void fireNotification(final String title, final String contentText, final String ticker, final int icon, final Intent intent, final boolean isOngoing) {
PendingIntent pendingIntent = null; PendingIntent pendingIntent = null;
if(intent != null) if(intent != null)
pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0); pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0);
/*
* Use the appropriate notificafation methods final NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
*/
if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) > 11){
final Builder builder = new Notification.Builder(getApplicationContext())
.setContentTitle(title) .setContentTitle(title)
.setContentText(contentText) .setContentText(contentText)
.setTicker(ticker) .setTicker(ticker)
.setSmallIcon(icon) .setSmallIcon(icon)
.setWhen(System.currentTimeMillis()); .setWhen(System.currentTimeMillis());
if(isOngoing)
builder.setOngoing(true); if(isOngoing)
else builder.setOngoing(true);
builder.setAutoCancel(true); else
if (intent != null) builder.setAutoCancel(true);
builder.setContentIntent(pendingIntent);
mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification()); if (intent != null)
} else { builder.setContentIntent(pendingIntent);
final Notification notification = new Notification(icon, title , System.currentTimeMillis()); mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification());
if(isOngoing)
notification.flags |= Notification.FLAG_ONGOING_EVENT;
else
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(getApplicationContext(), title, contentText, pendingIntent);
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
} }
/** /**
@@ -115,7 +101,6 @@ public class ReportPostingService extends Service {
android.R.drawable.stat_sys_upload, android.R.drawable.stat_sys_upload,
null, null,
true); true);
} }
/** /**

View File

@@ -27,7 +27,6 @@ public class VersionInformationPreference extends Preference {
private final Context mContext; private final Context mContext;
/** /**
* creates a preference that is nothing but a text view * creates a preference that is nothing but a text view
* @param context * @param context