问题描述
我正在开发一个android应用程序,旨在在屏幕上显示一个列表,其中包含用户词典中的内容.
I'm developing a android application which aims to show a list on the screen with the contents present in the user dictionary.
问题是,当我在Android API级别23内容提供程序中编译并运行应用程序时,会返回一个没有任何项目,没有任何数据的游标.
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.
这很奇怪,因为该应用程序的API之前的23(22、21、19等)会运行并正常在ListView中显示数据.
It's strange because the API's preceding 23 (22, 21, 19, ...) the app runs and displays the data in the ListView normally.
下面是我的活动代码:
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);
}
}
推荐答案
在此处报告了此问题: Android Issue Traker
This was reported here: Android Issue Traker
官方回应:按预期工作.自API 23起,该功能已被有效删除.
Official response: Working as intended. This feature has been remove effectively since API 23.
这篇关于在Android API级别23上访问UserDictionary内容提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!