Access to UserDictionary Content Provider at API Level 23

I am developing an Android application that is designed to display a list on the screen with the contents contained in a user dictionary.

The problem is that when I compile and run the application in Android API 23, the Content Provider returns a cursor without an element without any data.

This is strange because the API preceding 23 (22, 21, 19, ...) starts the application and usually displays the data in a ListView.

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); } } 
+5
source share
3 answers

This is reported here: Android Issue Traker

The official answer: Designation. This feature has been effectively removed from API 23.

+2
source

There was a problem at API level 23 where the user dictionary provider returns a cursor without data, even if the dictionary is full.

Current work - use a device or emulator running API level 22 or lower . You can quickly create an API level emulator.

0
source

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

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

0
source

Source: https://habr.com/ru/post/1237989/


All Articles