2

I'm trying to make a similar ContentProvider reading as in android developer guide- read from user dictionary. I can't get why my cursor has always 0 rows.. Of course I've added a needed permission. I was trying to change nulls to empty arrays or simmilar things, but it is not working. Any idea?

There is my source code

    public void sampleMethodWithContentProviders() {

//        String contentUriStr = "content://user_dictionary/words";
//        Uri wordsUri = Uri.parse(contentUriStr);

        String[] projectionString = {
                UserDictionary.Words._ID,
                UserDictionary.Words.WORD,
                UserDictionary.Words.LOCALE
        };

        String selectClause = null;

        String[] selectArgs = null;

        String order = null;

        Cursor cursor = getContentResolver().query(UserDictionary.Words.CONTENT_URI, projectionString, selectClause, selectArgs, order);


        Log.i("Cursor", cursor == null ? "null" : "obiekt");
        for (String s : cursor.getColumnNames())
            Log.i("Cursor column name: ", s);
        Log.i("Num of cursor element: ", Integer.toString(cursor.getCount()));
        while (cursor.moveToNext())
            Log.i("a", "b");
    }

And there the logs result

12-01 00:02:54.530 11693-11693/com.kros.withoutpain I/Cursor: obiekt 12-01 00:02:54.530 11693-11693/com.kros.withoutpain I/Cursor column name:: _id 12-01 00:02:54.530 11693-11693/com.kros.withoutpain I/Cursor column name:: word 12-01 00:02:54.530 11693-11693/com.kros.withoutpain I/Cursor column name:: locale 12-01 00:02:54.530 11693-11693/com.kros.withoutpain I/Num of cursor element:: 0

Krystian
  • 2,221
  • 1
  • 26
  • 41
  • 1
    There is no requirement for input methods to use the `UserDictionary` Provider, and many instead rely on their own internal lists or databases. If you don't have a keyboard on your device that uses the Provider, then your Dictionary will most likely be empty. – Mike M. Nov 30 '15 at 23:49
  • Are you testing on real device or emulator? Is it possible the dictionary is empty – Fletcher Johns Nov 30 '15 at 23:50
  • @FletcherJohns- I'm testing on device, probably the problem is as mentioned in comment above- Sony is preinstalling keyboard dedicated for xperia. – Krystian Dec 01 '15 at 20:59

1 Answers1

2

Access to the user dictionary was removed from Android from API 23 upwards, see this bug report... and this stack overflow question...

It seems this has been closed as "works as intended" seems there was some abuse of the feature, and so it was removed.

If you are experimenting with emulators you may want to try on one with and earlier APK. However I haven't had much luck rolling back as far as 21 ( Lollipop ). If you are just trying to experiment with cursors and content resolvers then I suggest Muhammad Farag's answer to a similar question

Vagnerr
  • 2,977
  • 3
  • 33
  • 46
  • Whoah, that was a question asked in 2015 :-) Anyway - despite having any possibility to test or check this, thank you for yout engagement :-) – Krystian Aug 17 '17 at 12:17