-
Notifications
You must be signed in to change notification settings - Fork 56
Fixing for Android 12 #123
Conversation
rguntha
commented
Oct 31, 2021
- Added PendingIntent.FLAG_IMMUTABLE for all the pending requests in AudiofilePlayerService.java and AudiofilePlayerPlugin.java
- Modified the MediaSessionCompat in the AudiofilePlayerService.onCreate method to send the FLAG_IMMUTABLE
- Added new MediaButtonReceiver12 class, modifying the static methods that create the PendingIntent and passing the FLAG_IMMUTABLE flag
java.lang.RuntimeException: Unable to create service com.google.flutter.plugins.audiofileplayer.AudiofileplayerService: java.lang.IllegalArgumentException: com.layamritam.app: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
| import android.support.v4.media.session.PlaybackStateCompat; | ||
| import android.util.Log; | ||
| import android.view.KeyEvent; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line
| ); | ||
|
|
||
| mediaSession = new MediaSessionCompat(this, TAG); | ||
| mediaSession = new MediaSessionCompat(this, TAG,null,pendingItent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add spaces after commas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this intent is only used up to KitKat:
https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat#MediaSessionCompat(android.content.Context,%20java.lang.String,%20android.content.ComponentName,%20android.app.PendingIntent)
- Does this library support KitKat or farther back?
- If so, add a comment highlighting that, so that if this library ever drops support for KitKat and previous, to remove this pendingIntent
| pendingIntent = PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_IMMUTABLE); | ||
| } | ||
| else | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use same style as elsewhere:
} else {
| } | ||
| else | ||
| { | ||
| pendingIntent = PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_UPDATE_CURRENT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to just pass
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT
in all cases? Or will that break on older OS versions?
|
|
||
| import java.util.List; | ||
|
|
||
| public class MediaButtonReceiver12{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space before open brace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a doc string to describe what this class does, and why it is needed beyond MediaButtonReceiver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this use case is already handled by a more recent version of AndroidX libraries:
https://developer.android.com/jetpack/androidx/releases/media#version_130_3
Seems like you can just change that dependency version and remove this file.
|
|
||
| public class MediaButtonReceiver12{ | ||
|
|
||
| public static ComponentName getMediaButtonReceiverComponent(Context context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private
| import java.util.List; | ||
|
|
||
| public class MediaButtonReceiver12{ | ||
| public class MediaButtonReceiver12 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this file if unused
This file is not needed as the updated media library 1.3.0 is sufficient
|
Dear @monkeyswarm,
I have implemented most/all of your comments. Please check.
The upgraded media library works.
I have tested on Android 12 and on Android 11.
Thanks very much
Ramesh
…On Mon, 1 Nov 2021 at 10:16, Daniel Iglesia ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
packages/audiofileplayer/android/src/main/java/com/google/flutter/plugins/audiofileplayer/MediaButtonReceiver12.java
<#123 (comment)>
:
> import java.util.List;
-public class MediaButtonReceiver12{
+public class MediaButtonReceiver12 {
Delete this file if unused
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#123 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA2WSBMTEIUF6SRJIYUPDYDUJYLUFANCNFSM5HCKFDNQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
Ramesh Guntha
|
Fixing for Android 12 (google#123)