Create NotificationFactory

This commit is contained in:
Benoit Marty 2023-04-14 17:49:47 +02:00
parent d280510dd9
commit efb620938c
6 changed files with 322 additions and 310 deletions

View file

@ -19,6 +19,7 @@ package io.element.android.libraries.androidutils.system
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.app.Activity
import android.app.NotificationManager
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
@ -72,6 +73,17 @@ fun Context.getApplicationLabel(packageName: String): String {
}
}
/**
* Return true it the user has enabled the do not disturb mode.
*/
fun isDoNotDisturbModeOn(context: Context): Boolean {
// We cannot use NotificationManagerCompat here.
val setting = context.getSystemService<NotificationManager>()!!.currentInterruptionFilter
return setting == NotificationManager.INTERRUPTION_FILTER_NONE ||
setting == NotificationManager.INTERRUPTION_FILTER_ALARMS
}
/**
* display the system dialog for granting this permission. If previously granted, the
* system will not show it (so you should call this method).