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
# Project target.
target=android-15
target=android-16

View File

@@ -14,7 +14,6 @@ import java.util.Date;
import java.util.Properties;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
@@ -27,6 +26,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
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
* @param generatedReportIntent
*/
@SuppressWarnings("deprecation")
private void displayNotification(final Intent generatedReportIntent) {
Log.i(TAG, "displayNotification");
final Context context = mContext.getApplicationContext();
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);
notifyDetails.setLatestEventInfo(context, context.getString(R.string.crash), context.getString(R.string.sorry), intent);
notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(context.getString(R.string.crash))
.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 android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
/**
@@ -48,38 +46,26 @@ public class ReportPostingService extends Service {
* @param isOngoing
* @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) {
PendingIntent pendingIntent = null;
if(intent != null)
pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0);
/*
* Use the appropriate notificafation methods
*/
if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) > 11){
final Builder builder = new Notification.Builder(getApplicationContext())
final NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
.setContentTitle(title)
.setContentText(contentText)
.setTicker(ticker)
.setSmallIcon(icon)
.setWhen(System.currentTimeMillis());
if(isOngoing)
builder.setOngoing(true);
else
builder.setAutoCancel(true);
if (intent != null)
builder.setContentIntent(pendingIntent);
mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification());
} else {
final Notification notification = new Notification(icon, title , System.currentTimeMillis());
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);
}
if(isOngoing)
builder.setOngoing(true);
else
builder.setAutoCancel(true);
if (intent != null)
builder.setContentIntent(pendingIntent);
mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification());
}
/**
@@ -115,7 +101,6 @@ public class ReportPostingService extends Service {
android.R.drawable.stat_sys_upload,
null,
true);
}
/**

View File

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