クラッシュレポート対応

This commit is contained in:
tateisu 2019-11-15 13:20:35 +09:00
parent 8b16d5fd69
commit 096a8770db
1 changed files with 46 additions and 42 deletions

View File

@ -4,56 +4,60 @@ 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)
val downloadManager =
context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager?
?: throw NotImplementedError("missing DownloadManager system service")
val query = DownloadManager.Query().setFilterById(id)
downloadManager.query(query)?.use { cursor ->
if(cursor.moveToFirst()) {
val title = cursor.getStringOrNull(DownloadManager.COLUMN_TITLE)
if(DownloadManager.STATUS_SUCCESSFUL == cursor.getIntOrNull(DownloadManager.COLUMN_STATUS)) {
/*
ダウンロード完了通知がシステムからのものと重複することがある
when(intent?.action) {
DownloadManager.ACTION_DOWNLOAD_COMPLETE -> {
val downloadManager =
context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
try {
val id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0L)
val query = DownloadManager.Query().setFilterById(id)
- (Aubee elm. Android 5.1) don't shows toast.
- (Samsung Galaxy S8+ Android 7.0) don't show toast.
- (Kyocera AndroidOne Android 8.0 S2) don't show toast.
- (LGE LGL24 Android 5.0.2) SHOWS toast.
- (LGE LGV32 Android 6.0) SHOWS toast.
maybe it depends on customization by device maker. not depends on OS version.
重複を回避する方法はなさそうだ
*/
showToast(
context,
false,
context.getString(R.string.download_complete, title)
)
} else {
showToast(
context,
false,
context.getString(R.string.download_failed, title)
)
downloadManager.query(query)?.use { cursor ->
if(! cursor.moveToFirst()) {
log.e("cursor.moveToFirst() failed.")
} else {
val title = cursor.getStringOrNull(DownloadManager.COLUMN_TITLE)
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)
}
)
/*
ダウンロード完了通知がシステムからのものと重複することがある
- (Aubee elm. Android 5.1) don't shows toast.
- (Samsung Galaxy S8+ Android 7.0) don't show toast.
- (Kyocera AndroidOne Android 8.0 S2) don't show toast.
- (LGE LGL24 Android 5.0.2) SHOWS toast.
- (LGE LGV32 Android 6.0) SHOWS toast.
maybe it depends on customization by device maker. not depends on OS version.
重複を回避する方法はなさそうだ
*/
}
}
} catch(ex : Throwable) {
log.e(ex, "downloadManager.query() failed.")
}
}
}