From 663f3fe47173be17cca466212481e3e86424a4d7 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 28 Apr 2012 20:17:49 -0400 Subject: [PATCH] Added an if block to run the right notification methods closes #21 Signed-off-by: Ricky Barrette --- .../exception/ReportPostingService.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ReportPostingService.java b/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ReportPostingService.java index b35927b..44bfb5d 100644 --- a/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ReportPostingService.java +++ b/ExceptionHandlerLib/src/com/TwentyCodes/android/exception/ReportPostingService.java @@ -11,6 +11,7 @@ import java.io.IOException; import org.apache.http.client.ClientProtocolException; import android.app.Notification; +import android.app.Notification.Builder; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; @@ -64,23 +65,24 @@ public class ReportPostingService extends Service { Context context = this.getApplicationContext(); mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - - Notification notification = new Notification(android.R.drawable.stat_sys_upload, getText(R.string.sending) , System.currentTimeMillis()); - notification.flags |= Notification.FLAG_ONGOING_EVENT; - notification.setLatestEventInfo(context, getText(R.string.sending_report), getText(R.string.sending), PendingIntent.getActivity(context, 0, null, 0)); - mNotificationManager.notify(NOTIFICATION_ID, notification); - /* - * for api 11+ + * Use the appropriate notificafation methods */ -// Builder builder = new Notification.Builder(context) -// .setContentTitle(getText(R.string.sending)) -// .setContentText(getText(R.string.sending_report)) -// .setTicker(getText(R.string.sending)) -// .setOngoing(true) -// .setSmallIcon(android.R.drawable.stat_sys_upload) -// .setWhen(System.currentTimeMillis()); - mNotificationManager.notify(NOTIFICATION_ID, notification); + if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) > 11){ + Builder builder = new Notification.Builder(context) + .setContentTitle(getText(R.string.sending)) + .setContentText(getText(R.string.sending_report)) + .setTicker(getText(R.string.sending)) + .setOngoing(true) + .setSmallIcon(android.R.drawable.stat_sys_upload) + .setWhen(System.currentTimeMillis()); + mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification()); + } else { + Notification notification = new Notification(android.R.drawable.stat_sys_upload, getText(R.string.sending) , System.currentTimeMillis()); + notification.flags |= Notification.FLAG_ONGOING_EVENT; + notification.setLatestEventInfo(context, getText(R.string.sending_report), getText(R.string.sending), PendingIntent.getActivity(context, 0, null, 0)); + mNotificationManager.notify(NOTIFICATION_ID, notification); + } super.onCreate(); } @@ -100,6 +102,7 @@ public class ReportPostingService extends Service { * (non-Javadoc) * @see android.app.Service#onStart(android.content.Intent, int) */ + @SuppressWarnings("deprecation") @Override public void onStart(Intent intent, int startId) { mStartId = startId;