create notification channel for export service

This commit is contained in:
Daniel Gultsch 2018-09-16 14:40:28 +02:00
parent c141f16065
commit 3624d11824
3 changed files with 114 additions and 103 deletions

View File

@ -6,6 +6,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
@ -56,7 +57,7 @@ public class ExportLogsService extends Service {
List<Conversation> conversations = mDatabaseBackend.getConversations(Conversation.STATUS_AVAILABLE);
conversations.addAll(mDatabaseBackend.getConversations(Conversation.STATUS_ARCHIVED));
NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext());
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext(), "export");
mBuilder.setContentTitle(getString(R.string.notification_export_logs_title))
.setSmallIcon(R.drawable.ic_import_export_white_24dp)
.setProgress(conversations.size(), 0, false);
@ -67,9 +68,11 @@ public class ExportLogsService extends Service {
writeToFile(conversation);
progress++;
mBuilder.setProgress(conversations.size(), progress, false);
if (mNotifyManager != null) {
mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());
}
}
}
private void writeToFile(Conversation conversation) {
Jid accountJid = resolveAccountUuid(conversation.getAccountUuid());

View File

@ -100,7 +100,7 @@ public class NotificationService {
@RequiresApi(api = Build.VERSION_CODES.O)
public void initializeChannels() {
final Context c = mXmppConnectionService;
NotificationManager notificationManager = c.getSystemService(NotificationManager.class);
final NotificationManager notificationManager = c.getSystemService(NotificationManager.class);
if (notificationManager == null) {
return;
}
@ -129,6 +129,13 @@ public class NotificationService {
videoCompressionChannel.setGroup("status");
notificationManager.createNotificationChannel(videoCompressionChannel);
final NotificationChannel exportChannel = new NotificationChannel("export",
c.getString(R.string.export_channel_name),
NotificationManager.IMPORTANCE_LOW);
exportChannel.setShowBadge(false);
exportChannel.setGroup("status");
notificationManager.createNotificationChannel(exportChannel);
final NotificationChannel messagesChannel = new NotificationChannel("messages",
c.getString(R.string.messages_channel_name),
NotificationManager.IMPORTANCE_HIGH);

View File

@ -736,4 +736,5 @@
<string name="video_compression_channel_name">Video compression</string>
<string name="view_media">View media</string>
<string name="media_browser">Media browser</string>
<string name="export_channel_name">History export</string>
</resources>