diff --git a/library/src/main/java/com/download/library/DownloadNotifier.java b/library/src/main/java/com/download/library/DownloadNotifier.java index eb7ecb0..584151d 100644 --- a/library/src/main/java/com/download/library/DownloadNotifier.java +++ b/library/src/main/java/com/download/library/DownloadNotifier.java @@ -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); @@ -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; } @@ -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);