クラッシュレポート対応

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