Quellcode durchsuchen

started updating intent calls. Crash when selecting day in alarm

yattoz vor 2 Jahren
Ursprung
Commit
185f0867e2

+ 2 - 1
app/src/main/java/fr/forum_thalie/tsumugi/BaseNotification.kt Datei anzeigen

@@ -50,6 +50,7 @@ abstract class BaseNotification(private val notificationChannelId: String,
50 50
         notificationManager.notify(notificationId, notification)
51 51
     }
52 52
 
53
+    @RequiresApi(Build.VERSION_CODES.M)
53 54
     open fun create(c: Context) {
54 55
         notificationManager = c.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
55 56
 
@@ -58,7 +59,7 @@ abstract class BaseNotification(private val notificationChannelId: String,
58 59
         // thanks to the launchMode specified in the Manifest : android:launchMode="singleTop"
59 60
         val pendingIntent = PendingIntent.getActivity(
60 61
             c, 0,
61
-            notificationIntent, 0
62
+            notificationIntent, PendingIntent.FLAG_IMMUTABLE
62 63
         )
63 64
         var channelID = ""
64 65
 

+ 8 - 5
app/src/main/java/fr/forum_thalie/tsumugi/NowPlayingNotification.kt Datei anzeigen

@@ -3,8 +3,10 @@ package fr.forum_thalie.tsumugi
3 3
 import android.app.PendingIntent
4 4
 import android.content.Context
5 5
 import android.content.Intent
6
+import android.os.Build
6 7
 import android.support.v4.media.session.MediaSessionCompat
7 8
 import android.support.v4.media.session.PlaybackStateCompat
9
+import androidx.annotation.RequiresApi
8 10
 import androidx.core.app.NotificationCompat
9 11
 import fr.forum_thalie.tsumugi.playerstore.PlayerStore
10 12
 
@@ -34,7 +36,7 @@ class NowPlayingNotification(
34 36
         // got it right
35 37
         val delIntent = Intent(c, RadioService::class.java)
36 38
         delIntent.putExtra("action", Actions.KILL.name)
37
-        val deleteIntent = PendingIntent.getService(c, 0, delIntent, PendingIntent.FLAG_NO_CREATE)
39
+        val deleteIntent = PendingIntent.getService(c, 0, delIntent, PendingIntent.FLAG_NO_CREATE + PendingIntent.FLAG_IMMUTABLE)
38 40
         builder.setDeleteIntent(deleteIntent)
39 41
 
40 42
         mediaStyle = androidx.media.app.NotificationCompat.DecoratedMediaCustomViewStyle().also {
@@ -46,6 +48,7 @@ class NowPlayingNotification(
46 48
         update(c)
47 49
     }
48 50
 
51
+    @RequiresApi(Build.VERSION_CODES.M)
49 52
     fun update(c: Context, isUpdatingNotificationButton: Boolean = false, isRinging: Boolean = false) {
50 53
 
51 54
         if (isUpdatingNotificationButton)
@@ -72,17 +75,17 @@ class NowPlayingNotification(
72 75
 
73 76
             playPauseAction = if (PlayerStore.instance.playbackState.value == PlaybackStateCompat.STATE_PLAYING) {
74 77
                 intent.putExtra("action", Actions.PAUSE.name)
75
-                val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
78
+                val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
76 79
                 NotificationCompat.Action.Builder(R.drawable.ic_pause, "Pause", pendingButtonIntent).build()
77 80
             } else {
78 81
                 intent.putExtra("action", Actions.PLAY.name)
79
-                val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
82
+                val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
80 83
                 NotificationCompat.Action.Builder(R.drawable.ic_play,"Play", pendingButtonIntent).build()
81 84
             }
82 85
             builder.addAction(playPauseAction)
83 86
             val intent2 = Intent(c, RadioService::class.java)
84 87
             intent2.putExtra("action", Actions.KILL.name)
85
-            val pendingButtonIntent = PendingIntent.getService(c, 2, intent2, PendingIntent.FLAG_UPDATE_CURRENT)
88
+            val pendingButtonIntent = PendingIntent.getService(c, 2, intent2, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
86 89
             val stopAction = NotificationCompat.Action.Builder(R.drawable.ic_close,"Stop", pendingButtonIntent).build()
87 90
             builder.addAction(stopAction)
88 91
 
@@ -92,7 +95,7 @@ class NowPlayingNotification(
92 95
 
93 96
                 val snoozeIntent = Intent(c, RadioService::class.java)
94 97
                 snoozeIntent.putExtra("action", Actions.SNOOZE.name)
95
-                val pendingSnoozeIntent = PendingIntent.getService(c, 5, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT)
98
+                val pendingSnoozeIntent = PendingIntent.getService(c, 5, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
96 99
                 val snoozeAction = NotificationCompat.Action.Builder(R.drawable.ic_alarm, "Snooze ($snoozeMinutes min.)", pendingSnoozeIntent ).build()
97 100
                 if (snoozeMinutes > 0)
98 101
                     builder.addAction(snoozeAction)

+ 2 - 1
app/src/main/java/fr/forum_thalie/tsumugi/RadioService.kt Datei anzeigen

@@ -193,7 +193,8 @@ class RadioService : MediaBrowserServiceCompat() {
193 193
 
194 194
         // Define managers
195 195
         telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
196
-        telephonyManager?.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
196
+        // telephonyManager?.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
197
+
197 198
         audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
198 199
 
199 200
         //define the audioFocusRequest

+ 24 - 3
app/src/main/java/fr/forum_thalie/tsumugi/alarm/RadioAlarm.kt Datei anzeigen

@@ -4,7 +4,9 @@ import android.app.AlarmManager
4 4
 import android.app.PendingIntent
5 5
 import android.content.Context
6 6
 import android.content.Intent
7
+import android.os.Build
7 8
 import android.util.Log
9
+import androidx.annotation.RequiresApi
8 10
 import androidx.core.app.AlarmManagerCompat
9 11
 import fr.forum_thalie.tsumugi.BootBroadcastReceiver
10 12
 import androidx.preference.PreferenceManager
@@ -27,11 +29,29 @@ class RadioAlarm {
27 29
     {
28 30
         alarmIntent = Intent(c, BootBroadcastReceiver::class.java).let { intent ->
29 31
             intent.putExtra("action", "$tag.${Actions.PLAY_OR_FALLBACK.name}")
30
-            PendingIntent.getBroadcast(c, 0, intent, 0)
32
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
33
+                PendingIntent.getBroadcast(
34
+                    c,
35
+                    0,
36
+                    intent,
37
+                    PendingIntent.FLAG_IMMUTABLE
38
+                )
39
+            } else {
40
+                PendingIntent.getBroadcast(
41
+                    c,
42
+                    0,
43
+                    intent,
44
+                    0
45
+                )
46
+            }
31 47
         }
32 48
         showIntent = Intent(c, ParametersActivity::class.java).let { intent ->
33 49
             intent.putExtra("action", "alarm")
34
-            PendingIntent.getActivity(c, 0, intent, 0)
50
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
51
+                PendingIntent.getActivity(c, 0, intent, PendingIntent.FLAG_IMMUTABLE)
52
+            } else {
53
+                PendingIntent.getActivity(c, 0, intent, 0)
54
+            }
35 55
         }
36 56
     }
37 57
 
@@ -43,6 +63,7 @@ class RadioAlarm {
43 63
         alarmManager.cancel(alarmIntent)
44 64
     }
45 65
 
66
+    @RequiresApi(Build.VERSION_CODES.M)
46 67
     fun setNextAlarm(c: Context, isForce: Boolean = false, forceTime: Int? = null, forceDays: Set<String>? = null)
47 68
     {
48 69
         defineIntents(c)
@@ -54,7 +75,7 @@ class RadioAlarm {
54 75
 
55 76
         val showIntent = Intent(c, ParametersActivity::class.java).let { intent ->
56 77
             intent.putExtra("action", ActionOpenParam.ALARM.name)
57
-            PendingIntent.getActivity(c, 0, intent, 0)
78
+            PendingIntent.getActivity(c, 0, intent, PendingIntent.FLAG_IMMUTABLE)
58 79
         }
59 80
         val time = findNextAlarmTime(c, forceTime, forceDays)
60 81
         if (time > 0)

+ 6 - 2
app/src/main/java/fr/forum_thalie/tsumugi/alarm/RadioSleeper.kt Datei anzeigen

@@ -4,7 +4,9 @@ import android.app.AlarmManager
4 4
 import android.app.PendingIntent
5 5
 import android.content.Context
6 6
 import android.content.Intent
7
+import android.os.Build
7 8
 import android.util.Log
9
+import androidx.annotation.RequiresApi
8 10
 import androidx.core.app.AlarmManagerCompat
9 11
 import androidx.lifecycle.MutableLiveData
10 12
 import androidx.preference.PreferenceManager
@@ -30,18 +32,20 @@ class RadioSleeper {
30 32
     private lateinit var sleepIntent: PendingIntent
31 33
     private lateinit var fadeOutIntent: PendingIntent
32 34
 
35
+    @RequiresApi(Build.VERSION_CODES.M)
33 36
     private fun defineIntents(c: Context)
34 37
     {
35 38
         sleepIntent = Intent(c, RadioService::class.java).let { intent ->
36 39
             intent.putExtra("action", Actions.KILL.name)
37
-            PendingIntent.getService(c, 99, intent, 0)
40
+            PendingIntent.getService(c, 99, intent, PendingIntent.FLAG_IMMUTABLE)
38 41
         }
39 42
         fadeOutIntent = Intent(c, RadioService::class.java).let { intent ->
40 43
             intent.putExtra("action", Actions.FADE_OUT.name)
41
-            PendingIntent.getService(c, 98, intent, 0)
44
+            PendingIntent.getService(c, 98, intent, PendingIntent.FLAG_IMMUTABLE)
42 45
         }
43 46
     }
44 47
 
48
+    @RequiresApi(Build.VERSION_CODES.M)
45 49
     fun setSleep(c: Context, isForce: Boolean = false, forceDuration: Long? = null)
46 50
     {
47 51
         defineIntents(c)