Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
changelog:
Browse files Browse the repository at this point in the history
fixed pending intent error above Android 12
  • Loading branch information
gokadzev committed Jun 11, 2022
1 parent 2c4a83b commit 98acb3e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies {
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.work:work-runtime:2.7.1'

testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ private void createBuilder(){
if (this.infos.dismissable){
builder.setOngoing(false);
Intent dismissIntent = new Intent("music-controls-destroy");
PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(context, 1, dismissIntent, 0);
PendingIntent dismissPendingIntent;
if (Build.VERSION.SDK_INT >= 23) {
dismissPendingIntent = PendingIntent.getBroadcast(context, 1, dismissIntent, PendingIntent.FLAG_IMMUTABLE);
} else {
dismissPendingIntent = PendingIntent.getBroadcast(context, 1, dismissIntent, 0);
}

builder.setDeleteIntent(dismissPendingIntent);
} else {
builder.setOngoing(true);
Expand Down Expand Up @@ -245,7 +251,12 @@ private void createBuilder(){
Intent resultIntent = new Intent(context, cordovaActivity.getClass());
resultIntent.setAction(Intent.ACTION_MAIN);
resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
PendingIntent resultPendingIntent;
if (Build.VERSION.SDK_INT >= 31) {
resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_MUTABLE);
} else {
resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
}
builder.setContentIntent(resultPendingIntent);

//Controls
Expand All @@ -254,34 +265,59 @@ private void createBuilder(){
if (this.infos.hasPrev){
nbControls++;
Intent previousIntent = new Intent("music-controls-previous");
PendingIntent previousPendingIntent = PendingIntent.getBroadcast(context, 1, previousIntent, 0);
PendingIntent previousPendingIntent;
if (Build.VERSION.SDK_INT >= 31) {
previousPendingIntent = PendingIntent.getBroadcast(context, 1, previousIntent, PendingIntent.FLAG_MUTABLE);
} else {
previousPendingIntent = PendingIntent.getBroadcast(context, 1, previousIntent, 0);
}
builder.addAction(createAction(this.infos.prevIcon, R.drawable.cmc_skip_previous, previousPendingIntent));
}
if (this.infos.isPlaying){
/* Pause */
nbControls++;
Intent pauseIntent = new Intent("music-controls-pause");
PendingIntent pausePendingIntent = PendingIntent.getBroadcast(context, 1, pauseIntent, 0);
PendingIntent pausePendingIntent;
if (Build.VERSION.SDK_INT >= 31) {
pausePendingIntent = PendingIntent.getBroadcast(context, 1, pauseIntent, PendingIntent.FLAG_MUTABLE);
} else {
pausePendingIntent = PendingIntent.getBroadcast(context, 1, pauseIntent, 0);
}
builder.addAction(createAction(this.infos.pauseIcon, R.drawable.cmc_pause, pausePendingIntent));
} else {
/* Play */
nbControls++;
Intent playIntent = new Intent("music-controls-play");
PendingIntent playPendingIntent = PendingIntent.getBroadcast(context, 1, playIntent, 0);
PendingIntent playPendingIntent;
if (Build.VERSION.SDK_INT >= 31) {
playPendingIntent = PendingIntent.getBroadcast(context, 1, playIntent, PendingIntent.FLAG_MUTABLE);
} else {
playPendingIntent = PendingIntent.getBroadcast(context, 1, playIntent, 0);
}
builder.addAction(createAction(this.infos.playIcon, R.drawable.cmc_play, playPendingIntent));
}
/* Next */
if (this.infos.hasNext){
nbControls++;
Intent nextIntent = new Intent("music-controls-next");
PendingIntent nextPendingIntent = PendingIntent.getBroadcast(context, 1, nextIntent, 0);
PendingIntent nextPendingIntent;
if (Build.VERSION.SDK_INT >= 31) {
nextPendingIntent = PendingIntent.getBroadcast(context, 1, nextIntent, PendingIntent.FLAG_MUTABLE);
} else {
nextPendingIntent = PendingIntent.getBroadcast(context, 1, nextIntent, 0);
}
builder.addAction(createAction(this.infos.nextIcon, R.drawable.cmc_skip_next, nextPendingIntent));
}
/* Close */
if (this.infos.hasClose){
nbControls++;
Intent destroyIntent = new Intent("music-controls-destroy");
PendingIntent destroyPendingIntent = PendingIntent.getBroadcast(context, 1, destroyIntent, 0);
PendingIntent destroyPendingIntent;
if (Build.VERSION.SDK_INT >= 31) {
destroyPendingIntent = PendingIntent.getBroadcast(context, 1, destroyIntent, PendingIntent.FLAG_MUTABLE);
} else {
destroyPendingIntent = PendingIntent.getBroadcast(context, 1, destroyIntent, 0);
}
builder.addAction(createAction(this.infos.closeIcon, R.drawable.cmc_stop, destroyPendingIntent));
}

Expand Down

0 comments on commit 98acb3e

Please sign in to comment.