Saturday, 20 February 2021

Why ContentResolver returns channels but empty PreviewPrograms?

I request ContentContainer for Android-TV channels via:

@SuppressLint("RestrictedApi")
fun getPreviewPrograms(context: Context): List<PreviewProgram> {
    val progList: MutableList<PreviewProgram> = mutableListOf()
    try {
        val cursor = context.contentResolver.query(
            TvContractCompat.Channels.CONTENT_URI,
            proj,
            null,
            null,
            null
        )
        if (cursor != null && cursor.moveToFirst()) {
            do {
                val program = PreviewProgram.fromCursor(cursor)
                progList.add(program)
            } while (cursor.moveToNext())
        }
        cursor?.close()
    } catch (exc: IllegalArgumentException) {
        Log.e("XXX", "Error for preview programs", exc)
    }
    return progList
}

with proj like:

private val proj = arrayOf(
    TvContractCompat.Channels._ID,
    TvContractCompat.Channels.COLUMN_INTERNAL_PROVIDER_ID,
    TvContractCompat.Channels.COLUMN_BROWSABLE,
    TvContractCompat.Channels.COLUMN_INTERNAL_PROVIDER_DATA
)

and I call this function and get my PreviewPrograms by:

val pp = getPreviewPrograms(this)
Log.d("XXX", "SIZE ${pp.size}")
Log.d("XXX", pp.toString())

According to the logcat for last two log outputs:

? D/XXX: SIZE 3

? D/XXX: [PreviewProgram{browsable=1 _id=1}, PreviewProgram{browsable=1 _id=2}, PreviewProgram{browsable=1 _id=3}]

Obviously I have 3 PreviewProgram objects, which should contain further program information, but:

for(p in pp){
   Log.e("XXX","Program infos ${p.id} : ${p.description} : ${p.longDescription}")
}

returns

? E/XXX: ... Program infos 1 : null : null ? E/XXX: ... Program infos 2 : null : null ? E/XXX: ... Program infos 3 : null : null



from Why ContentResolver returns channels but empty PreviewPrograms?

No comments:

Post a Comment