5

I'm developing a android application which aims to show a list on the screen with the contents present in the user dictionary.

The problem is that when I compile and run the application in the Android API Level 23 Content Provider return a Cursor with no item, without any data.

It's strange because the API's preceding 23 (22, 21, 19, ...) the app runs and displays the data in the ListView normally.

Below is the code of my Activity:

import android.app.LoaderManager;
import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.provider.UserDictionary;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {

private ListView listView;
private SimpleCursorAdapter adapter;
private static final String[] COLUMNS = {
        UserDictionary.Words.WORD,
        UserDictionary.Words._ID,
        UserDictionary.Words.LOCALE
};

private static final int[] LIST_ITEM_VIEWS = {
        R.id.name,
        R.id.id_word,
        R.id.locale
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    listView = (ListView) findViewById(R.id.list);

    adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.item_list, null, COLUMNS, LIST_ITEM_VIEWS, 0);

    listView.setAdapter(adapter);

    getLoaderManager().initLoader(0, null, this);

}

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(getApplicationContext(), UserDictionary.Words.CONTENT_URI, COLUMNS,
            null, null, UserDictionary.Words.WORD);
}

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    adapter.swapCursor(data);

}

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    adapter.swapCursor(null);
}
}
Kesley Vaz
  • 51
  • 2
  • inside `onLoadFinished` call `DatabaseUtils#dumpCursor`, what do you see? – pskink Dec 12 '15 at 19:03
  • When I use the DatabaseUtils.dumpCursor() I get the following returns: On API level 23 = > "System.out: > > > > > cursor Dumping android. content. $ @ b465803 < CursorWrapperInner ContentResolver < < < <" On API level 22 = > "> > > > > cursor Dumping android. content. $ CursorWrapperInner @ 1a8ca936 ContentResolver 0 { Word = bluu _ id = 2 locale = null } 1 { Word = blooo _id = 1 locale = en_US } <<<<<" On API level 23 when I use the method getCount() from Cursor object, the same returns zero. – Kesley Vaz Dec 13 '15 at 21:50
  • so check your custom ContentProvider "query" method why it returns an empty Cursor – pskink Dec 13 '15 at 22:00
  • I already checked the query and it only returns empty on API level 23 – Kesley Vaz Dec 13 '15 at 22:16

3 Answers3

2

This was reported here: Android Issue Traker

Official response: Working as intended. This feature has been remove effectively since API 23.

Michael Jota
  • 138
  • 8
0

There is an issue on API level 23 where the user dictionary provider returns a cursor with no data, even when the dictionary is populated.

A current work around is to use a device or emulator running API level 22 or lower. You can quickly make an API level 22 emulator.

Basheer AL-MOMANI
  • 14,473
  • 9
  • 96
  • 92
0

According to the Android official document of UserDictionary, only IME and SpellChecker can access the UserDictionary.

Check the NOTE on this page: https://developer.android.com/reference/android/provider/UserDictionary.html