JPM*_*JPM 6 notifications android android-intent android-pendingintent
我正在尝试解决通知问题。
在我的应用程序中,当有人单击列表项以下载文件时,我正在创建一个通知(具有不确定的进度和随机生成的整数代码)。在下载的回调中,我使用与原始通知相同的ID更新通知以停止进度。单击通知应打开电话上的下载文件夹(使用待定意图)。此时一切都很好。
我遇到的问题是,当我单击多行以下载文件时,通知进行了分组。单击分组的通知会导致应用重新启动,而不是未决的打开意图。这是预期的行为吗?如果不是,我如何确保每当用户单击分组的通知时,都会下载文件夹并打开应用程序而不会重新启动?
到目前为止,这就是我所拥有的。
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());
Run Code Online (Sandbox Code Playgroud)
有什么想法我做错了吗?
归档时间: |
|
查看次数: |
152 次 |
最近记录: |