android-cursor

SQLite CursorWindow limit - How to avoid crash

冷暖自知 提交于 2020-01-01 17:04:09
问题 I have to execute a query and store the result in a list, the function that I use is this follow : List<SpoolInDB> getSpoolInRecords(String label, boolean getLastInserted) { List<SpoolInDB> spoolInList = new ArrayList<>(); try { if (mdb == null) mdb = mdbHelper.getWritableDatabase(); SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(TABLE_SPOOLIN); Cursor c = qb.query(mdb, null, " label='" + label + "'", null, null, null, " dateins " + (getLastInserted ? "desc" : "asc")); if (c !

How to get the No of track from an Artist in mediastore

断了今生、忘了曾经 提交于 2019-12-25 18:02:59
问题 I am trying to get the no of track in Artist table using mediastore. I am able to get all the artist name but when I try to get the NUMBER_OF_TRACKS I am getting error .I searched and found this But this is not the problem in my case .Here is my code try { String[] proj = {MediaStore.Audio.Artists._ID, MediaStore.Audio.Artists.ARTIST, MediaStore.Audio.ArtistsColumns.NUMBER_OF_TRACKS, MediaStore.Audio.Artists.ARTIST_KEY ,MediaStore.Audio.Artists.NUMBER_OF_ALBUMS };// Can include more data for

How to fetch recent and favourite contacts in android?

为君一笑 提交于 2019-12-25 09:19:59
问题 I have been trying to fetch recent and favorites contacts but every time i get error . i am storing contacts in database after fetching . cannot read column -1 and sometimes it says cursor not initialized properly. please help me . Here is my code. ContentResolver cr = getActivity().getContentResolver(); /* Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null );*/ Cursor cur=cr.query(CallLog.Calls.CONTENT_URI,null,CallLog.Calls.DATE, null,null); String phone =

Android - Adding Columns to Matrix Cursor and Showing Column Count Toast causing Crash

浪尽此生 提交于 2019-12-25 08:48:17
问题 Im using a matrix cursor to add rows to cursor. Defined columns in the MainActivity on Create //In protected void onCreate String[] columns = new String[] { "dealername", "product","type","description","location","sublocation","address","phone1","phone2","auth","brands","lat","lon"}; cursor= new MatrixCursor(columns); //----------------- In asyctask doinbackground cursor.addRow(new String[] {json.getString("dealername"),json.getString("product"), json.getString("type"),json.getString(

Android - Cursor onMapReady (Markers)

本小妞迷上赌 提交于 2019-12-25 06:27:57
问题 I'm trying to "inflate" my content from SQLite into Markers but the solution I took of here it's not working, and it's not throwing any information on Log. I'm a bit new on this Marker stuff and SQLite My code inside the Fragment : SQLiteHelper dbHelper = new SQLiteHelper(getActivity()); pds = new ParksDataSource(dbHelper.db); parks = pds.getAllParks(); List<Marker> markersList = new ArrayList<Marker>(); int i = 0; Cursor cursor = db.rawQuery("SELECT * FROM " + SQLiteHelper.TABLE_PARKS, null)

No “number_of_albums column” in MediaStore.Audio.Artists

我的梦境 提交于 2019-12-24 17:00:58
问题 I want to retrieve data from MediaStore especially the number of albums per artist but SQLite throws me an exception no such column: number_of_albums (code 1): while compiling: SELECT artist_key, artist, number_of_albums FROM audio WHERE (is_music != 0) Can someone explain me what I am doing wrong? My code : private List<Artist> getArtistList() { String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"; String[] projection = { MediaStore.Audio.Artists.ARTIST_KEY, MediaStore.Audio.Artists

How to close a cursor used in a for loop

时光总嘲笑我的痴心妄想 提交于 2019-12-24 16:05:47
问题 Background I have a cursor used as follows: for (int n=0; n<num_songs; n++) { boolean isChecked = checked_positions.get(n); if (isChecked) { Cursor cursor = (Cursor) getListView().getItemAtPosition(n); String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)); String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); cursor.close(); //save artist and title strings to file... } } This gives a StaleDataException on the second time round

Expandable listview with cursor

十年热恋 提交于 2019-12-24 12:48:46
问题 i want to make an expandable listview, but the adapter will take cursor as input instead of array list. i would like to implement animation on collapse, https://github.com/idunnololz/AnimatedExpandableListView/ i refereed this lib, i'm now am able to implement listview by passing list to the adapter. But is there a tweak we can do so that, this adapter can make it work with cursor?. My expanded child list consists of only icons. Data will sit in group view 来源: https://stackoverflow.com

Android ContentObserver- determine the SMS status

柔情痞子 提交于 2019-12-24 11:36:08
问题 I've registered a ContentObserver to the URI of Telephony.Sms.CONTENT_URI , in order to be notified every time the user sends or receives a new SMS message. For successfully-sent and received messages, this works fine - but for messages that have failed to send, I noticed an unexpected behavior: The messages seem to be reported as if they were successfully sent, even though they're not - and I couldn't find any indication about the failure. Inside the obeserver's onChange function, I tried to

How can an Android cursor be at a negative position?

六月ゝ 毕业季﹏ 提交于 2019-12-24 11:14:07
问题 While learning to iterate over a cursor, I learned that I needed to first move to position "-1" and then use "moveToNext" in a loop: cursor.moveToPosition(-1); for (int i = 0; cursor.moveToNext(); i++) { //do something with the cursor } While mathematically this makes sense, I don't know what it means to move to a cursor to a negative position. The documentation just says it's valid–doesn't seem to say how it's used. Is this used ONLY to make iteration possible, or is there other use cases