Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion app/src/main/java/io/heckel/ntfy/msg/BroadcastService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.heckel.ntfy.msg

import android.content.Context
import android.content.Intent
import android.net.Uri
import io.heckel.ntfy.R
import io.heckel.ntfy.db.Action
import io.heckel.ntfy.db.Notification
Expand Down Expand Up @@ -83,10 +84,25 @@ class BroadcastService(private val ctx: Context) {
else -> 0
}
val delay = getStringExtra(intent,"delay") ?: ""
val fileUriString = getStringExtra(intent, "file_uri")
val filenameOverride = getStringExtra(intent, "filename") ?: ""
GlobalScope.launch(Dispatchers.IO) {
val repository = Repository.getInstance(ctx)
val user = repository.getUser(baseUrl) // May be null
try {
val (body, filename) = if (fileUriString != null) {
val uri = Uri.parse(fileUriString)
if (uri.scheme != "content") {
Log.w(TAG, "file_uri must use the content:// scheme, got '${uri.scheme}'. Aborting.")
return@launch
}
// fileStat() throws on invalid/missing URI; caught below
val stat = fileStat(ctx, uri)
val body = ContentUriRequestBody(ctx.contentResolver, uri, stat.size)
Pair(body, filenameOverride.ifEmpty { stat.filename })
} else {
Pair(null, "") // filename ignored when no file_uri
}
Log.d(TAG, "Publishing message $intent")
api.publish(
baseUrl = baseUrl,
Expand All @@ -96,7 +112,9 @@ class BroadcastService(private val ctx: Context) {
title = title,
priority = priority,
tags = splitTags(tags),
delay = delay
delay = delay,
body = body,
filename = filename,
)
} catch (e: Exception) {
Log.w(TAG, "Unable to publish message: ${e.message}", e)
Expand Down