Use NotificationChannelCompat features

This commit is contained in:
TacoTheDank 2021-09-24 21:28:11 -04:00
parent c78cc8aaec
commit 14a09c725f
5 changed files with 47 additions and 59 deletions

View File

@ -1,8 +1,6 @@
package ml.docilealligator.infinityforreddit.services;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ContentResolver;
@ -22,6 +20,7 @@ import android.os.Message;
import android.os.Process;
import android.provider.MediaStore;
import androidx.core.app.NotificationChannelCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.documentfile.provider.DocumentFile;
@ -367,16 +366,13 @@ public class DownloadMediaService extends Service {
int mediaType = intent.getIntExtra(EXTRA_MEDIA_TYPE, EXTRA_MEDIA_TYPE_IMAGE);
builder = new NotificationCompat.Builder(this, getNotificationChannelId(mediaType));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel serviceChannel;
serviceChannel = new NotificationChannel(
NotificationChannelCompat serviceChannel =
new NotificationChannelCompat.Builder(
getNotificationChannelId(mediaType),
getNotificationChannel(mediaType),
NotificationManager.IMPORTANCE_LOW
);
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(getNotificationChannel(mediaType))
.build();
notificationManager.createNotificationChannel(serviceChannel);
}
int randomNotificationIdOffset = new Random().nextInt(10000);
switch (intent.getIntExtra(EXTRA_MEDIA_TYPE, EXTRA_MEDIA_TYPE_IMAGE)) {

View File

@ -1,8 +1,6 @@
package ml.docilealligator.infinityforreddit.services;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ContentResolver;
@ -26,6 +24,7 @@ import android.os.Message;
import android.os.Process;
import android.provider.MediaStore;
import androidx.core.app.NotificationChannelCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.documentfile.provider.DocumentFile;
@ -501,16 +500,13 @@ public class DownloadRedditVideoService extends Service {
String subredditName = intent.getStringExtra(EXTRA_SUBREDDIT);
String fileNameWithoutExtension = subredditName + "-" + intent.getStringExtra(EXTRA_POST_ID);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel serviceChannel;
serviceChannel = new NotificationChannel(
NotificationChannelCompat serviceChannel =
new NotificationChannelCompat.Builder(
NotificationUtils.CHANNEL_ID_DOWNLOAD_REDDIT_VIDEO,
NotificationUtils.CHANNEL_DOWNLOAD_REDDIT_VIDEO,
NotificationManager.IMPORTANCE_LOW
);
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(NotificationUtils.CHANNEL_DOWNLOAD_REDDIT_VIDEO)
.build();
notificationManager.createNotificationChannel(serviceChannel);
}
int randomNotificationIdOffset = new Random().nextInt(10000);
startForeground(

View File

@ -1,16 +1,14 @@
package ml.docilealligator.infinityforreddit.services;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationChannelCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
@ -60,16 +58,17 @@ public class MaterialYouService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
((Infinity) getApplication()).getAppComponent().inject(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel serviceChannel = new NotificationChannel(
NotificationChannelCompat serviceChannel =
new NotificationChannelCompat.Builder(
NotificationUtils.CHANNEL_ID_MATERIAL_YOU,
NotificationUtils.CHANNEL_MATERIAL_YOU,
NotificationManager.IMPORTANCE_LOW
);
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(NotificationUtils.CHANNEL_MATERIAL_YOU)
.build();
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.createNotificationChannel(serviceChannel);
}
Notification notification = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_MATERIAL_YOU)
.setContentTitle(getString(R.string.material_you_notification_title))
.setContentText(getString(R.string.please_wait))

View File

@ -1,13 +1,10 @@
package ml.docilealligator.infinityforreddit.services;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
@ -19,6 +16,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationChannelCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
@ -164,16 +162,15 @@ public class SubmitPostService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
((Infinity) getApplication()).getAppComponent().inject(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel serviceChannel = new NotificationChannel(
NotificationChannelCompat serviceChannel =
new NotificationChannelCompat.Builder(
NotificationUtils.CHANNEL_SUBMIT_POST,
NotificationUtils.CHANNEL_SUBMIT_POST,
NotificationManager.IMPORTANCE_LOW
);
NotificationManagerCompat.IMPORTANCE_LOW)
.setName(NotificationUtils.CHANNEL_SUBMIT_POST)
.build();
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.createNotificationChannel(serviceChannel);
}
int randomNotificationIdOffset = new Random().nextInt(10000);
int postType = intent.getIntExtra(EXTRA_POST_TYPE, EXTRA_POST_TEXT_OR_LINK);

View File

@ -1,10 +1,8 @@
package ml.docilealligator.infinityforreddit.utils;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import androidx.core.app.NotificationChannelCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
@ -40,10 +38,11 @@ public class NotificationUtils {
Context context, String title, String content,
String summary, String channelId, String channelName,
String group, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
NotificationChannelCompat channel =
new NotificationChannelCompat.Builder(channelId, NotificationManagerCompat.IMPORTANCE_DEFAULT)
.setName(channelName)
.build();
notificationManager.createNotificationChannel(channel);
}
return new NotificationCompat.Builder(context.getApplicationContext(), channelId)
.setContentTitle(title)
@ -60,10 +59,11 @@ public class NotificationUtils {
public static NotificationCompat.Builder buildSummaryNotification(Context context, NotificationManagerCompat notificationManager,
String title, String content, String channelId,
String channelName, String group, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
NotificationChannelCompat channel =
new NotificationChannelCompat.Builder(channelId, NotificationManagerCompat.IMPORTANCE_DEFAULT)
.setName(channelName)
.build();
notificationManager.createNotificationChannel(channel);
}
return new NotificationCompat.Builder(context, channelId)
.setContentTitle(title)