Search code examples
androidtelevisionandroid-tv

Returning MatrixCursor in ContentProvider query method makes Android TV global search crash


I'm trying to make my Android TV app searchable, and I'm testing the global search. I've created a ContentProvider and it's query method is called when I search something. The problem comes when I populate a cursor and I return it, in that moment the global search crashes and the LogCat shows nothing about this. My code in this section is this:

MatrixCursor matrixCursor = new MatrixCursor(new String[]{
        "_id",
        SearchManager.SUGGEST_COLUMN_TEXT_1,
        SearchManager.SUGGEST_COLUMN_CONTENT_TYPE,
        SearchManager.SUGGEST_COLUMN_PRODUCTION_YEAR,
        SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
        SearchManager.SUGGEST_COLUMN_INTENT_DATA,
        SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID
});

matrixCursor.addRow(new Object[]{
        1,
        "movie 1",
        "video/mp4",
        2014,
        Intent.ACTION_SEARCH,
        "content://myauthority/videos/",
        1
});

matrixCursor.addRow(new Object[]{
        2,
        "video 2",
        "video/mp4",
        2013,
        Intent.ACTION_SEARCH,
        "content://myauthority/videos/",
        2
});

matrixCursor.addRow(new Object[]{
        2,
        "video 3",
        "video/mp4",
        2012,
        Intent.ACTION_SEARCH,
        "content://myauthority/videos/",
        3
});

return matrixCursor;

I'm just trying to return a test cursor to see how global search works, but I must be doing something wrong.


Solution

  • I found the problem. I thought that only SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_CONTENT_TYPE and SearchManager.SUGGEST_COLUMN_PRODUCTION_YEAR fields were required (that's what Android developers TV guide says), but SearchManager.SUGGEST_COLUMN_RESULT_CARD_IMAGE is also required. Without the card image the global search crashes, probably because tries to set a null bitmap.