Updater: Add notification channels

Change-Id: I2f538fb47fe90e1008bf286739d33c829123353a
This commit is contained in:
Harry Youd
2017-09-27 22:33:00 +01:00
committed by LuK1337
parent 0e79b791f0
commit ff53035537
4 changed files with 39 additions and 5 deletions

View File

@@ -16,6 +16,7 @@
package org.lineageos.updater;
import android.app.AlarmManager;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
@@ -24,7 +25,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.v7.app.NotificationCompat;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import org.json.JSONException;
@@ -46,6 +47,9 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
private static final String DAILY_CHECK_ACTION = "daily_check_action";
private static final String ONESHOT_CHECK_ACTION = "oneshot_check_action";
private static final String NEW_UPDATES_NOTIFICATION_CHANNEL =
"new_updates_notification_channel";
@Override
public void onReceive(final Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
@@ -121,7 +125,12 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
private static void showNotification(Context context) {
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
NotificationChannel notificationChannel = new NotificationChannel(
NEW_UPDATES_NOTIFICATION_CHANNEL,
context.getString(R.string.new_updates_channel_title),
NotificationManager.IMPORTANCE_LOW);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,
NEW_UPDATES_NOTIFICATION_CHANNEL);
notificationBuilder.setSmallIcon(R.drawable.ic_system_update);
Intent notificationIntent = new Intent(context, UpdatesActivity.class);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
@@ -129,6 +138,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
notificationBuilder.setContentIntent(intent);
notificationBuilder.setContentTitle(context.getString(R.string.new_updates_found_title));
notificationBuilder.setAutoCancel(true);
notificationManager.createNotificationChannel(notificationChannel);
notificationManager.notify(0, notificationBuilder.build());
}