Android: Clicking Grouped Notifications Restarts App

耗尽温柔 提交于 2019-12-07 03:27:22

问题


I am trying to solve an issue that I am experiencing with notifications.

In my app, I am creating a notification (with an indeterminate progress and a randomly generated integer code) when someone clicks a list item to download a file. On the callback of the download, I update the notification to stop the progress, using the same id of the original notification. Clicking a notification is supposed to open the downloads folder on the phone (using a pending intent). All is well at this point.

The issue I am experiencing is when I click on multiple rows to download files, the notifications are grouped. Clicking on the grouped notification results in the app being restarted, and not the pending intent to open. Is this expected behaviour? If not, how can I ensure whenever the user clicks a grouped notification, the downloads folder is opened and the app is not restarted?

This is what I have so far.

Intent downloadFilesIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);

PendingIntent pendingIntent = PendingIntent.getActivity(MyActivity.this, MY_CODE, downloadFilesIntent, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), BuildConfig.NOTIFICATION_DOWNLOAD_FILE_CHANNEL)
          .setSmallIcon(R.mipmap.ic_launcher)
          .setWhen(System.currentTimeMillis())
          .setAutoCancel(true)
          .setContentTitle("File downloaded")
          .setContentIntent(pendingIntent)
          .setProgress(0, 0, false)
          .setContentText("myFileName.txt");
notificationManager.notify(downloadId, builder.build());

Any ideas what I am doing wrong?

来源:https://stackoverflow.com/questions/47703216/android-clicking-grouped-notifications-restarts-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!