mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 13:45:35 +03:00
FilesExportWork: use getActivity for PendingIntent
With the broadcast, the notification drawer will not autoclose to show the file browser, which is not good UX. With this approach the notification will not be autodismissed, but that's the lesser of two evils. Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
1d69dcfcaa
commit
db4e9887b1
2 changed files with 3 additions and 36 deletions
|
@ -156,9 +156,6 @@
|
|||
<receiver
|
||||
android:name="com.nextcloud.client.jobs.NotificationWork$NotificationReceiver"
|
||||
android:exported="false" />
|
||||
<receiver
|
||||
android:name="com.nextcloud.client.jobs.FilesExportWork$NotificationReceiver"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.activity.UploadFilesActivity"
|
||||
|
|
|
@ -22,18 +22,14 @@
|
|||
|
||||
package com.nextcloud.client.jobs
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.DownloadManager
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.BitmapFactory
|
||||
import android.widget.Toast
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
|
@ -154,10 +150,10 @@ class FilesExportWork(
|
|||
.setContentText(message)
|
||||
.setAutoCancel(true)
|
||||
|
||||
val actionIntent = Intent(appContext, NotificationReceiver::class.java).apply {
|
||||
putExtra(NUMERIC_NOTIFICATION_ID, notificationId)
|
||||
val actionIntent = Intent(DownloadManager.ACTION_VIEW_DOWNLOADS).apply {
|
||||
flags = FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
val actionPendingIntent = PendingIntent.getBroadcast(
|
||||
val actionPendingIntent = PendingIntent.getActivity(
|
||||
appContext,
|
||||
notificationId,
|
||||
actionIntent,
|
||||
|
@ -174,30 +170,4 @@ class FilesExportWork(
|
|||
val notificationManager = appContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(notificationId, notificationBuilder.build())
|
||||
}
|
||||
|
||||
class NotificationReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
// open file chooser
|
||||
val openIntent = Intent(DownloadManager.ACTION_VIEW_DOWNLOADS).apply {
|
||||
flags = FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
|
||||
// check if intent can be resolved
|
||||
if (context.packageManager.queryIntentActivities(openIntent, PackageManager.GET_RESOLVED_FILTER)
|
||||
.isNotEmpty()
|
||||
) {
|
||||
context.startActivity(openIntent)
|
||||
} else {
|
||||
Toast.makeText(context, R.string.open_download_folder, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
// remove notification
|
||||
val numericNotificationId = intent.getIntExtra(NUMERIC_NOTIFICATION_ID, 0)
|
||||
|
||||
if (numericNotificationId != 0) {
|
||||
val notificationManager = context.getSystemService(Activity.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.cancel(numericNotificationId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue