Created
October 29, 2018 20:01
-
-
Save roberto-o-r/4a8008ce80be27e9f2c5e986cb2e86f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.isscroberto.powernap.util | |
import android.app.Service | |
import android.content.Context | |
import android.content.Intent | |
import android.media.Ringtone | |
import android.media.RingtoneManager | |
import android.os.IBinder | |
class AlarmService : Service() { | |
private lateinit var ringtone: Ringtone | |
override fun onBind(p0: Intent?): IBinder? { | |
return null | |
} | |
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | |
playAlarm() | |
return super.onStartCommand(intent, flags, startId) | |
} | |
override fun onDestroy() { | |
super.onDestroy() | |
ringtone.stop() | |
} | |
fun playAlarm() { | |
val notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM) | |
ringtone = RingtoneManager.getRingtone(this, notification) | |
if(!ringtone.isPlaying()) { | |
ringtone.play() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment