forked from TeamNewPipe/NewPipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow customizing notification actions on Android 13+
Use a workaround initially suggested in TeamNewPipe#10567 Basically tell the system that we're not able to handle "prev" and "next", in order to have 4 customizable action slots instead of just 2 On Android 13+ normal notification actions are useless, so they are not set into the notification builder anymore, to save battery The opposite happens on Android 12-, where media session actions are not set because they don't seem to do anything
- Loading branch information
Showing
4 changed files
with
204 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/main/java/org/schabi/newpipe/player/mediasession/SessionConnectorActionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.schabi.newpipe.player.mediasession; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v4.media.session.PlaybackStateCompat; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.google.android.exoplayer2.Player; | ||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector; | ||
|
||
import org.schabi.newpipe.player.notification.NotificationActionData; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
public class SessionConnectorActionProvider implements MediaSessionConnector.CustomActionProvider { | ||
|
||
private final NotificationActionData data; | ||
@NonNull | ||
private final WeakReference<Context> context; | ||
|
||
public SessionConnectorActionProvider(final NotificationActionData notificationActionData, | ||
@NonNull final Context context) { | ||
this.data = notificationActionData; | ||
this.context = new WeakReference<>(context); | ||
} | ||
|
||
@Override | ||
public void onCustomAction(@NonNull final Player player, | ||
@NonNull final String action, | ||
@Nullable final Bundle extras) { | ||
final Context actualContext = context.get(); | ||
if (actualContext != null) { | ||
actualContext.sendBroadcast(new Intent(action)); | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public PlaybackStateCompat.CustomAction getCustomAction(@NonNull final Player player) { | ||
if (data.action() == null) { | ||
return null; | ||
} else { | ||
return new PlaybackStateCompat.CustomAction.Builder( | ||
data.action(), data.name(), data.icon() | ||
).build(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters