import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import androidx.core.app.NotificationManagerCompat
import java.lang.Exception
/**
* Create by: liuan
* Create date: 2021-11-24 0024
* Describe:
*/
object NotificationManager {
fun isNotificationEnabled(context: Context): Boolean {
var isOpened = false
isOpened = try {
NotificationManagerCompat.from(context).areNotificationsEnabled()
} catch (e: Exception) {
e.printStackTrace()
false
}
return isOpened
}
fun gotoSet(context: Context) {
val intent = Intent()
if (Build.VERSION.SDK_INT >= 26) {
// android 8.0引导
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS")
intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName())
} else if (Build.VERSION.SDK_INT >= 21) {
// android 5.0-7.0
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS")
intent.putExtra("app_package", context.getPackageName())
intent.putExtra("app_uid", context.getApplicationInfo().uid)
} else {
// 其他
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS")
intent.setData(Uri.fromParts("package", context.getPackageName(), null))
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}
}
|