| Proyecto Integral de Ingeniería del Software | |
|---|---|
| Metodologías Ágiles |
| Trabajo Fin De Grado | |
|---|---|
| Guía Memoria TFG |
| Servidores | |
|---|---|
| Minercraft | |
| Knoppia | |
| Omegacraft |
| Base de datos de juegos | |
|---|---|
| GameBoy Advance (GBA) |
| Proyecto Integral de Ingeniería del Software | |
|---|---|
| Metodologías Ágiles |
| Trabajo Fin De Grado | |
|---|---|
| Guía Memoria TFG |
| Servidores | |
|---|---|
| Minercraft | |
| Knoppia | |
| Omegacraft |
| Base de datos de juegos | |
|---|---|
| GameBoy Advance (GBA) |
¡Esta es una revisión vieja del documento!
Debemos tener establecido el siguiente permiso en AndroidManifest.xml:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
Primero crearemos las constantes con el nombre del canal, el ID del canal y el ID de la notificación que crearemos al inicio de la clase de nuestra activity:
private val nombreCanal = "depanama"
private val idCanal = "retrovisu"
private val idNotificacion = 5
Después, donde termina la función onCreate crearemos un canal de notificaciones, que es necesario para dispositivos con android 8 y superior:
private fun crearCanalNotificacion(){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){//Comprobamos la versión
val importanciaCanal = NotificationManager.IMPORTANCE_HIGH //establecemos la importancia del canal
val canal = NotificationChannel(idCanal, nombreCanal, importanciaCanal) //definimos el canal
//Creamos gestor de notificaciones:
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.createNotificationChannel(canal)//Creamos el canal de notificaciones
}
}
Finalmente crearemos la función para lanzar la notificación:
private fun crearNotificacion(){
crearCanalNotificacion()//Creamos canal de comunicación
val notificacion = NotificationCompat.Builder(this,idCanal).also {
it.setContentTitle("Título Notificación")
it.setContentText("Cuerpo notificación")
it.setSmallIcon(R.drawable.foto)//icono de la notificación
it.priority = NotificationCompat.PRIORITY_HIGH//establecemos prioridad
}.build()
val GestorNotificaciones = NotificationManagerCompat.from(this)
//revisamos que estén puestos los permisos en AndroidManifest.xml
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(applicationContext,"No hay permisos de notificaciones", Toast.LENGTH_SHORT)
return
}
GestorNotificaciones.notify(idNotificacion, notificacion)
}