Fixed updater on Android N. Closes #592 (#595)

This commit is contained in:
Bram van de Kerkhof
2016-12-21 00:34:31 +01:00
committed by GitHub
parent 2241a0b2de
commit 7fdd2cacd7
5 changed files with 47 additions and 57 deletions
@@ -45,14 +45,14 @@ class ImageNotificationReceiver : BroadcastReceiver() {
* Called to start share intent to share image
*
* @param context context of application
* @param path path of file
* @param file file that contains image
*/
internal fun shareImageIntent(context: Context, path: String): PendingIntent {
internal fun shareImageIntent(context: Context, file: File): PendingIntent {
val intent = Intent(Intent.ACTION_SEND).apply {
val uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", File(path))
val uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", file)
putExtra(Intent.EXTRA_STREAM, uri)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
type = "image/*"
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
@@ -61,15 +61,15 @@ class ImageNotificationReceiver : BroadcastReceiver() {
* Called to show image in gallery application
*
* @param context context of application
* @param path path of file
* @param file file that contains image
*/
internal fun showImageIntent(context: Context, path: String): PendingIntent {
internal fun showImageIntent(context: Context, file: File): PendingIntent {
val intent = Intent(Intent.ACTION_VIEW).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
val uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", File(path))
val uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", file)
setDataAndType(uri, "image/*")
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getActivity(context, 0, intent, 0)
}
internal fun deleteImageIntent(context: Context, path: String, notificationId: Int): PendingIntent {
@@ -58,11 +58,11 @@ class ImageNotifier(private val context: Context) {
if (!mActions.isEmpty())
mActions.clear()
setContentIntent(ImageNotificationReceiver.showImageIntent(context, file.absolutePath))
setContentIntent(ImageNotificationReceiver.showImageIntent(context, file))
// Share action
addAction(R.drawable.ic_share_grey_24dp,
context.getString(R.string.action_share),
ImageNotificationReceiver.shareImageIntent(context, file.absolutePath))
context.getString(R.string.action_share),
ImageNotificationReceiver.shareImageIntent(context, file))
// Delete action
addAction(R.drawable.ic_delete_grey_24dp,
context.getString(R.string.action_delete),