fix: set required (im)mutable flag when creating pending intent
When targeting SDK S+ (version 31 and above) a (im)mutable flags is required when creating a PendingInent.
This commit is contained in:
parent
6a6405ccdc
commit
0a48cb5016
@ -54,9 +54,10 @@ class VideoPlayActivity : CommonActivity() {
|
|||||||
val videoPlayerFragment =
|
val videoPlayerFragment =
|
||||||
fragmentManager.findFragmentById(R.id.video_player_fragment) as VideoPlayerFragment?
|
fragmentManager.findFragmentById(R.id.video_player_fragment) as VideoPlayerFragment?
|
||||||
val actions = ArrayList<RemoteAction>()
|
val actions = ArrayList<RemoteAction>()
|
||||||
|
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0
|
||||||
var actionIntent = Intent(getString(R.string.app_background_audio))
|
var actionIntent = Intent(getString(R.string.app_background_audio))
|
||||||
var pendingIntent =
|
var pendingIntent =
|
||||||
PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, 0)
|
PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, flags)
|
||||||
@SuppressLint("NewApi", "LocalSuppress") var icon = Icon.createWithResource(
|
@SuppressLint("NewApi", "LocalSuppress") var icon = Icon.createWithResource(
|
||||||
applicationContext, android.R.drawable.stat_sys_speakerphone
|
applicationContext, android.R.drawable.stat_sys_speakerphone
|
||||||
)
|
)
|
||||||
@ -65,7 +66,7 @@ class VideoPlayActivity : CommonActivity() {
|
|||||||
actions.add(remoteAction)
|
actions.add(remoteAction)
|
||||||
actionIntent = Intent(PlayerNotificationManager.ACTION_STOP)
|
actionIntent = Intent(PlayerNotificationManager.ACTION_STOP)
|
||||||
pendingIntent =
|
pendingIntent =
|
||||||
PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, 0)
|
PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, flags)
|
||||||
icon = Icon.createWithResource(
|
icon = Icon.createWithResource(
|
||||||
applicationContext,
|
applicationContext,
|
||||||
com.google.android.exoplayer2.ui.R.drawable.exo_notification_stop
|
com.google.android.exoplayer2.ui.R.drawable.exo_notification_stop
|
||||||
@ -77,7 +78,7 @@ class VideoPlayActivity : CommonActivity() {
|
|||||||
Log.e(TAG, "setting actions with play button")
|
Log.e(TAG, "setting actions with play button")
|
||||||
actionIntent = Intent(PlayerNotificationManager.ACTION_PLAY)
|
actionIntent = Intent(PlayerNotificationManager.ACTION_PLAY)
|
||||||
pendingIntent =
|
pendingIntent =
|
||||||
PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, 0)
|
PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, flags)
|
||||||
icon = Icon.createWithResource(
|
icon = Icon.createWithResource(
|
||||||
applicationContext,
|
applicationContext,
|
||||||
com.google.android.exoplayer2.ui.R.drawable.exo_notification_play
|
com.google.android.exoplayer2.ui.R.drawable.exo_notification_play
|
||||||
@ -87,7 +88,7 @@ class VideoPlayActivity : CommonActivity() {
|
|||||||
Log.e(TAG, "setting actions with pause button")
|
Log.e(TAG, "setting actions with pause button")
|
||||||
actionIntent = Intent(PlayerNotificationManager.ACTION_PAUSE)
|
actionIntent = Intent(PlayerNotificationManager.ACTION_PAUSE)
|
||||||
pendingIntent =
|
pendingIntent =
|
||||||
PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, 0)
|
PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, flags)
|
||||||
icon = Icon.createWithResource(
|
icon = Icon.createWithResource(
|
||||||
applicationContext,
|
applicationContext,
|
||||||
com.google.android.exoplayer2.ui.R.drawable.exo_notification_pause
|
com.google.android.exoplayer2.ui.R.drawable.exo_notification_pause
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.schueller.peertube.service
|
package net.schueller.peertube.service
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
import net.schueller.peertube.helper.MetaDataHelper.getMetaString
|
import net.schueller.peertube.helper.MetaDataHelper.getMetaString
|
||||||
import net.schueller.peertube.model.Video.Companion.getMediaDescription
|
import net.schueller.peertube.model.Video.Companion.getMediaDescription
|
||||||
@ -46,6 +47,7 @@ import android.content.BroadcastReceiver
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.webkit.URLUtil
|
import android.webkit.URLUtil
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
@ -217,11 +219,15 @@ class VideoPlayerService : Service() {
|
|||||||
return currentVideo!!.name
|
return currentVideo!!.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("UnspecifiedImmutableFlag")
|
||||||
override fun createCurrentContentIntent(player: Player): PendingIntent? {
|
override fun createCurrentContentIntent(player: Player): PendingIntent? {
|
||||||
val intent = Intent(context, VideoPlayActivity::class.java)
|
val intent = Intent(context, VideoPlayActivity::class.java)
|
||||||
intent.putExtra(VideoListActivity.EXTRA_VIDEOID, currentVideo!!.uuid)
|
intent.putExtra(VideoListActivity.EXTRA_VIDEOID, currentVideo!!.uuid)
|
||||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
|
||||||
|
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
|
PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||||
|
else
|
||||||
|
PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCurrentContentText(player: Player): CharSequence {
|
override fun getCurrentContentText(player: Player): CharSequence {
|
||||||
|
Loading…
Reference in New Issue
Block a user