started updating intent calls. Crash when selecting day in alarm
parent
63d18856f1
commit
185f0867e2
|
|
@ -50,6 +50,7 @@ abstract class BaseNotification(private val notificationChannelId: String,
|
|||
notificationManager.notify(notificationId, notification)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
open fun create(c: Context) {
|
||||
notificationManager = c.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
||||
|
|
@ -58,7 +59,7 @@ abstract class BaseNotification(private val notificationChannelId: String,
|
|||
// thanks to the launchMode specified in the Manifest : android:launchMode="singleTop"
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
c, 0,
|
||||
notificationIntent, 0
|
||||
notificationIntent, PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
var channelID = ""
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ package fr.forum_thalie.tsumugi
|
|||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.support.v4.media.session.MediaSessionCompat
|
||||
import android.support.v4.media.session.PlaybackStateCompat
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.NotificationCompat
|
||||
import fr.forum_thalie.tsumugi.playerstore.PlayerStore
|
||||
|
||||
|
|
@ -34,7 +36,7 @@ class NowPlayingNotification(
|
|||
// got it right
|
||||
val delIntent = Intent(c, RadioService::class.java)
|
||||
delIntent.putExtra("action", Actions.KILL.name)
|
||||
val deleteIntent = PendingIntent.getService(c, 0, delIntent, PendingIntent.FLAG_NO_CREATE)
|
||||
val deleteIntent = PendingIntent.getService(c, 0, delIntent, PendingIntent.FLAG_NO_CREATE + PendingIntent.FLAG_IMMUTABLE)
|
||||
builder.setDeleteIntent(deleteIntent)
|
||||
|
||||
mediaStyle = androidx.media.app.NotificationCompat.DecoratedMediaCustomViewStyle().also {
|
||||
|
|
@ -46,6 +48,7 @@ class NowPlayingNotification(
|
|||
update(c)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
fun update(c: Context, isUpdatingNotificationButton: Boolean = false, isRinging: Boolean = false) {
|
||||
|
||||
if (isUpdatingNotificationButton)
|
||||
|
|
@ -72,17 +75,17 @@ class NowPlayingNotification(
|
|||
|
||||
playPauseAction = if (PlayerStore.instance.playbackState.value == PlaybackStateCompat.STATE_PLAYING) {
|
||||
intent.putExtra("action", Actions.PAUSE.name)
|
||||
val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_pause, "Pause", pendingButtonIntent).build()
|
||||
} else {
|
||||
intent.putExtra("action", Actions.PLAY.name)
|
||||
val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_play,"Play", pendingButtonIntent).build()
|
||||
}
|
||||
builder.addAction(playPauseAction)
|
||||
val intent2 = Intent(c, RadioService::class.java)
|
||||
intent2.putExtra("action", Actions.KILL.name)
|
||||
val pendingButtonIntent = PendingIntent.getService(c, 2, intent2, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val pendingButtonIntent = PendingIntent.getService(c, 2, intent2, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
|
||||
val stopAction = NotificationCompat.Action.Builder(R.drawable.ic_close,"Stop", pendingButtonIntent).build()
|
||||
builder.addAction(stopAction)
|
||||
|
||||
|
|
@ -92,7 +95,7 @@ class NowPlayingNotification(
|
|||
|
||||
val snoozeIntent = Intent(c, RadioService::class.java)
|
||||
snoozeIntent.putExtra("action", Actions.SNOOZE.name)
|
||||
val pendingSnoozeIntent = PendingIntent.getService(c, 5, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val pendingSnoozeIntent = PendingIntent.getService(c, 5, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
|
||||
val snoozeAction = NotificationCompat.Action.Builder(R.drawable.ic_alarm, "Snooze ($snoozeMinutes min.)", pendingSnoozeIntent ).build()
|
||||
if (snoozeMinutes > 0)
|
||||
builder.addAction(snoozeAction)
|
||||
|
|
|
|||
|
|
@ -193,7 +193,8 @@ class RadioService : MediaBrowserServiceCompat() {
|
|||
|
||||
// Define managers
|
||||
telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||
telephonyManager?.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
|
||||
// telephonyManager?.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
|
||||
|
||||
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
|
||||
//define the audioFocusRequest
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import android.app.AlarmManager
|
|||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.AlarmManagerCompat
|
||||
import fr.forum_thalie.tsumugi.BootBroadcastReceiver
|
||||
import androidx.preference.PreferenceManager
|
||||
|
|
@ -27,11 +29,29 @@ class RadioAlarm {
|
|||
{
|
||||
alarmIntent = Intent(c, BootBroadcastReceiver::class.java).let { intent ->
|
||||
intent.putExtra("action", "$tag.${Actions.PLAY_OR_FALLBACK.name}")
|
||||
PendingIntent.getBroadcast(c, 0, intent, 0)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
PendingIntent.getBroadcast(
|
||||
c,
|
||||
0,
|
||||
intent,
|
||||
PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
} else {
|
||||
PendingIntent.getBroadcast(
|
||||
c,
|
||||
0,
|
||||
intent,
|
||||
0
|
||||
)
|
||||
}
|
||||
}
|
||||
showIntent = Intent(c, ParametersActivity::class.java).let { intent ->
|
||||
intent.putExtra("action", "alarm")
|
||||
PendingIntent.getActivity(c, 0, intent, 0)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
PendingIntent.getActivity(c, 0, intent, PendingIntent.FLAG_IMMUTABLE)
|
||||
} else {
|
||||
PendingIntent.getActivity(c, 0, intent, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,6 +63,7 @@ class RadioAlarm {
|
|||
alarmManager.cancel(alarmIntent)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
fun setNextAlarm(c: Context, isForce: Boolean = false, forceTime: Int? = null, forceDays: Set<String>? = null)
|
||||
{
|
||||
defineIntents(c)
|
||||
|
|
@ -54,7 +75,7 @@ class RadioAlarm {
|
|||
|
||||
val showIntent = Intent(c, ParametersActivity::class.java).let { intent ->
|
||||
intent.putExtra("action", ActionOpenParam.ALARM.name)
|
||||
PendingIntent.getActivity(c, 0, intent, 0)
|
||||
PendingIntent.getActivity(c, 0, intent, PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
val time = findNextAlarmTime(c, forceTime, forceDays)
|
||||
if (time > 0)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import android.app.AlarmManager
|
|||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.AlarmManagerCompat
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.preference.PreferenceManager
|
||||
|
|
@ -30,18 +32,20 @@ class RadioSleeper {
|
|||
private lateinit var sleepIntent: PendingIntent
|
||||
private lateinit var fadeOutIntent: PendingIntent
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun defineIntents(c: Context)
|
||||
{
|
||||
sleepIntent = Intent(c, RadioService::class.java).let { intent ->
|
||||
intent.putExtra("action", Actions.KILL.name)
|
||||
PendingIntent.getService(c, 99, intent, 0)
|
||||
PendingIntent.getService(c, 99, intent, PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
fadeOutIntent = Intent(c, RadioService::class.java).let { intent ->
|
||||
intent.putExtra("action", Actions.FADE_OUT.name)
|
||||
PendingIntent.getService(c, 98, intent, 0)
|
||||
PendingIntent.getService(c, 98, intent, PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
fun setSleep(c: Context, isForce: Boolean = false, forceDuration: Long? = null)
|
||||
{
|
||||
defineIntents(c)
|
||||
|
|
|
|||
Loading…
Reference in New Issue