BeemService: Use NotificationManagerCompat
authorFrederic Barthelery <da_risk@beem-project.com>
Fri, 13 Nov 2015 17:50:23 +0100
changeset 1067 029597e0ca0c
parent 1066 744a173ea554
child 1068 51bf3e7db33a
BeemService: Use NotificationManagerCompat
app/src/main/java/com/beem/project/beem/BeemService.java
app/src/main/java/com/beem/project/beem/service/XmppConnectionAdapter.java
--- a/app/src/main/java/com/beem/project/beem/BeemService.java	Tue Oct 27 01:12:06 2015 +0100
+++ b/app/src/main/java/com/beem/project/beem/BeemService.java	Fri Nov 13 17:50:23 2015 +0100
@@ -52,7 +52,6 @@
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.app.Notification;
-import android.app.NotificationManager;
 import android.app.Service;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -66,6 +65,7 @@
 import android.os.RemoteException;
 import android.preference.PreferenceManager;
 import android.provider.Settings;
+import android.support.v4.app.NotificationManagerCompat;
 import android.util.Log;
 
 import com.beem.project.beem.service.XmppConnectionAdapter;
@@ -122,7 +122,7 @@
     private static final String TAG = "BeemService";
     private static final int DEFAULT_XMPP_PORT = 5222;
 
-    private NotificationManager mNotificationManager;
+    private NotificationManagerCompat mNotificationManager;
     private XmppConnectionAdapter mConnection;
     private SharedPreferences mSettings;
     private String mLogin;
@@ -284,7 +284,7 @@
 
 	configure(ProviderManager.getInstance());
 
-	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+	mNotificationManager = NotificationManagerCompat.from(this);
 
 	Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
 
@@ -393,7 +393,7 @@
      * Get the notification manager system service.
      * @return the notification manager service.
      */
-    public NotificationManager getNotificationManager() {
+    public NotificationManagerCompat getNotificationManager() {
 	return mNotificationManager;
     }
 
--- a/app/src/main/java/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Oct 27 01:12:06 2015 +0100
+++ b/app/src/main/java/com/beem/project/beem/service/XmppConnectionAdapter.java	Fri Nov 13 17:50:23 2015 +0100
@@ -54,6 +54,7 @@
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
 import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.NotificationManagerCompat;
 import android.util.Log;
 
 import com.beem.project.beem.BeemApplication;
@@ -369,13 +370,16 @@
      * @param text the text to display.
      */
     private void updateNotification(int status, String text) {
-	Notification mStatusNotification;
-	mStatusNotification = new Notification(Status.getIconBarFromStatus(status), text, System.currentTimeMillis());
-	mStatusNotification.defaults = Notification.DEFAULT_LIGHTS;
-	mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
+	NotificationCompat.Builder builder = new NotificationCompat.Builder(mService);
+	Notification mStatusNotification = builder.setSmallIcon(Status.getIconBarFromStatus(status))
+		.setContentText(text)
+		.setContentTitle("Beem Status")
+		.setDefaults(NotificationCompat.DEFAULT_LIGHTS)
+		.setWhen(System.currentTimeMillis())
+		.setOngoing(true)
+		.setContentIntent(PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0))
+		.build();
 
-	mStatusNotification.setLatestEventInfo(mService, "Beem Status", text,
-	    PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0));
 	// bypass the preferences for notification
 	mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
     }