Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PendingIntent FLAG_IMMUTABLE or FLAG_MUTABLE flag issue at target version 31 #27

Merged
merged 3 commits into from
Feb 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions library/src/main/java/com/download/library/DownloadNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ private static DispatchThread getNotificationUpdateQueue() {

void initBuilder(DownloadTask downloadTask) {
String title = getTitle(downloadTask);
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags |= PendingIntent.FLAG_IMMUTABLE;
}
this.mDownloadTask = downloadTask;
mBuilder.setContentIntent(PendingIntent.getActivity(mContext, 200, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT));
mBuilder.setContentIntent(PendingIntent.getActivity(mContext, 200, new Intent(), flags));
mBuilder.setSmallIcon(mDownloadTask.getDownloadIcon());
mBuilder.setTicker(mContext.getString(R.string.download_trickter));
mBuilder.setContentTitle(title);
Expand Down Expand Up @@ -139,7 +143,11 @@ private String getTitle(DownloadTask downloadTask) {
private PendingIntent buildCancelContent(Context context, int id, String url) {
Intent intentCancel = new Intent(Runtime.getInstance().append(context, NotificationCancelReceiver.ACTION));
intentCancel.putExtra("TAG", url);
PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(context, id * 1000, intentCancel, PendingIntent.FLAG_UPDATE_CURRENT);
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags |= PendingIntent.FLAG_IMMUTABLE;
}
PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(context, id * 1000, intentCancel, flags);
Runtime.getInstance().log(TAG, "buildCancelContent id:" + (id * 1000) + " cancal action:" + Runtime.getInstance().append(context, NotificationCancelReceiver.ACTION));
return pendingIntentCancel;
}
Expand Down Expand Up @@ -280,10 +288,12 @@ void onDownloadFinished() {
public void run() {
removeCancelAction();
setDelecte(null);
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags |= PendingIntent.FLAG_IMMUTABLE;
}
PendingIntent rightPendIntent = PendingIntent
.getActivity(mContext,
mNotificationId * 10000, mIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
.getActivity(mContext, mNotificationId * 10000, mIntent, flags);
mBuilder.setSmallIcon(mDownloadTask.getDownloadDoneIcon());
mBuilder.setContentText(mContext.getString(R.string.download_click_open));
mBuilder.setProgress(100, 100, false);
Expand Down