playback: fix notification launch issue
Fix an accidental regression where PendingIntent.getBroadcast was called for activities, causing the notification launch intent not to work.
This commit is contained in:
parent
d50d2f0b1e
commit
ffebbc2839
3 changed files with 18 additions and 15 deletions
|
@ -20,7 +20,6 @@ import org.oxycblt.auxio.ui.isNight
|
||||||
/**
|
/**
|
||||||
* The single [AppCompatActivity] for Auxio.
|
* The single [AppCompatActivity] for Auxio.
|
||||||
* TODO: Port widgets to non-12 android
|
* TODO: Port widgets to non-12 android
|
||||||
* TODO: Change how I handle lifecycle owners
|
|
||||||
* TODO: Fix intent issues
|
* TODO: Fix intent issues
|
||||||
*/
|
*/
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
|
@ -30,12 +30,22 @@ class PlaybackNotification private constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
mediaToken: MediaSessionCompat.Token
|
mediaToken: MediaSessionCompat.Token
|
||||||
) : NotificationCompat.Builder(context, CHANNEL_ID), PlaybackStateManager.Callback {
|
) : NotificationCompat.Builder(context, CHANNEL_ID), PlaybackStateManager.Callback {
|
||||||
|
private val pendingIntentFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
|
PendingIntent.FLAG_IMMUTABLE
|
||||||
|
else 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
val activityIntent = PendingIntent.getActivity(
|
||||||
|
context, REQUEST_CODE,
|
||||||
|
Intent(context, MainActivity::class.java),
|
||||||
|
pendingIntentFlags
|
||||||
|
)
|
||||||
|
|
||||||
setSmallIcon(R.drawable.ic_song)
|
setSmallIcon(R.drawable.ic_song)
|
||||||
setCategory(NotificationCompat.CATEGORY_SERVICE)
|
setCategory(NotificationCompat.CATEGORY_SERVICE)
|
||||||
setShowWhen(false)
|
setShowWhen(false)
|
||||||
setSilent(true)
|
setSilent(true)
|
||||||
setContentIntent(newPendingIntent(context, Intent(context, MainActivity::class.java)))
|
setContentIntent(activityIntent)
|
||||||
setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
|
|
||||||
addAction(buildLoopAction(context, LoopMode.NONE))
|
addAction(buildLoopAction(context, LoopMode.NONE))
|
||||||
|
@ -152,23 +162,15 @@ class PlaybackNotification private constructor(
|
||||||
): NotificationCompat.Action {
|
): NotificationCompat.Action {
|
||||||
val action = NotificationCompat.Action.Builder(
|
val action = NotificationCompat.Action.Builder(
|
||||||
iconRes, actionName,
|
iconRes, actionName,
|
||||||
newPendingIntent(context, Intent(actionName))
|
PendingIntent.getBroadcast(
|
||||||
|
context, REQUEST_CODE,
|
||||||
|
Intent(actionName), pendingIntentFlags
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return action.build()
|
return action.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun newPendingIntent(context: Context, intent: Intent): PendingIntent {
|
|
||||||
return PendingIntent.getBroadcast(
|
|
||||||
context, REQUEST_CODE, intent,
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
||||||
PendingIntent.FLAG_IMMUTABLE
|
|
||||||
} else {
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val CHANNEL_ID = "CHANNEL_AUXIO_PLAYBACK"
|
const val CHANNEL_ID = "CHANNEL_AUXIO_PLAYBACK"
|
||||||
const val NOTIFICATION_ID = 0xA0A0
|
const val NOTIFICATION_ID = 0xA0A0
|
||||||
|
|
|
@ -84,7 +84,9 @@ abstract class BaseWidget : AppWidgetProvider() {
|
||||||
android.R.id.background,
|
android.R.id.background,
|
||||||
PendingIntent.getActivity(
|
PendingIntent.getActivity(
|
||||||
context, 0xA0A0, Intent(context, MainActivity::class.java),
|
context, 0xA0A0, Intent(context, MainActivity::class.java),
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
|
PendingIntent.FLAG_IMMUTABLE
|
||||||
|
else 0
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue