クラッシュレポート対応
This commit is contained in:
parent
8b16d5fd69
commit
096a8770db
|
@ -4,30 +4,43 @@ import android.app.DownloadManager
|
|||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import jp.juggler.util.LogCategory
|
||||
import jp.juggler.util.getIntOrNull
|
||||
import jp.juggler.util.getStringOrNull
|
||||
import jp.juggler.util.showToast
|
||||
|
||||
class DownloadReceiver : BroadcastReceiver() {
|
||||
|
||||
companion object {
|
||||
private val log = LogCategory("DownloadReceiver")
|
||||
}
|
||||
|
||||
override fun onReceive(context : Context, intent : Intent?) {
|
||||
intent ?: return
|
||||
|
||||
val action = intent.action ?: return
|
||||
|
||||
if(DownloadManager.ACTION_DOWNLOAD_COMPLETE == action) {
|
||||
val id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0L)
|
||||
when(intent?.action) {
|
||||
DownloadManager.ACTION_DOWNLOAD_COMPLETE -> {
|
||||
|
||||
val downloadManager =
|
||||
context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager?
|
||||
?: throw NotImplementedError("missing DownloadManager system service")
|
||||
context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||
|
||||
try {
|
||||
val id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0L)
|
||||
val query = DownloadManager.Query().setFilterById(id)
|
||||
|
||||
downloadManager.query(query)?.use { cursor ->
|
||||
if(cursor.moveToFirst()) {
|
||||
|
||||
if(! cursor.moveToFirst()) {
|
||||
log.e("cursor.moveToFirst() failed.")
|
||||
} else {
|
||||
val title = cursor.getStringOrNull(DownloadManager.COLUMN_TITLE)
|
||||
|
||||
if(DownloadManager.STATUS_SUCCESSFUL == cursor.getIntOrNull(DownloadManager.COLUMN_STATUS)) {
|
||||
val status = cursor.getIntOrNull(DownloadManager.COLUMN_STATUS)
|
||||
showToast(
|
||||
context,
|
||||
false,
|
||||
if(status == DownloadManager.STATUS_SUCCESSFUL) {
|
||||
context.getString(R.string.download_complete, title)
|
||||
} else {
|
||||
context.getString(R.string.download_failed, title)
|
||||
}
|
||||
)
|
||||
/*
|
||||
ダウンロード完了通知がシステムからのものと重複することがある
|
||||
|
||||
|
@ -41,19 +54,10 @@ class DownloadReceiver : BroadcastReceiver() {
|
|||
|
||||
重複を回避する方法はなさそうだ…
|
||||
*/
|
||||
|
||||
showToast(
|
||||
context,
|
||||
false,
|
||||
context.getString(R.string.download_complete, title)
|
||||
)
|
||||
} else {
|
||||
showToast(
|
||||
context,
|
||||
false,
|
||||
context.getString(R.string.download_failed, title)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(ex : Throwable) {
|
||||
log.e(ex, "downloadManager.query() failed.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue