android-cursor

How to update existing contact?

元气小坏坏 提交于 2019-11-28 23:11:43
I have one existing contact, I need to add a work address to that existing contact. I am using the following code, but it's not working. String selectPhone = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + "'" + " AND " + ContactsContract.CommonDataKinds.StructuredPostal.TYPE + "=?"; String[] phoneArgs = new String[] {String.valueOf(ContactId), String.valueOf( ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK)}; ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI) .withSelection(selectPhone, phoneArgs)

Query songs of an album with CursorLoader

巧了我就是萌 提交于 2019-11-28 21:42:03
问题 I'd like to get the list of songs of an album by querying the MediaStore with CursorLoader How can i do this ? I can get all the songs of the device with this code : static final String[] TRACK_SUMMARY_PROJECTION = { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE}; public Loader<Cursor> onCreateLoader(int id, Bundle args) { String sortOrder = MediaStore.Audio.Media.TITLE + " ASC"; String select = null; return new CursorLoader(getActivity(), MediaStore.Audio.Media.EXTERNAL_CONTENT

Using CursorLoader with LoaderManager to retrieve images from android apps

谁说我不能喝 提交于 2019-11-28 14:08:52
At the moment I’m using getContentResolver().query()/managedQuery() to get a cursor to retrieve images from the gallery app. Because the APIs I’m using are partly deprecated I wanted to use CursorLoader with LoaderManager. /** * Creates a cursor to access the content defined by the image uri for API * version 11 and newer. * * @return The created cursor. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private Cursor createCursorHoneycomb() { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(imageUri, projection, null, null, null); return cursor; }

Inverted ListView in Android?

霸气de小男生 提交于 2019-11-28 12:11:54
Is there an easy way to display a ListView in reverse order? I am trying to create a conversation-based app, and would like the most recent entries to be at the bottom of the ListView. I am aware of transcriptMode and stackFromBottom, however my problem is the order of the data. Say I have 100 conversation items, and want to display items 80-100, with 100 being the most recent conversation item. I would like to show 80-100, which implies an ORDER BY id desc LIMIT 20 in my query, which forces the items to be sorted 100 to 80, the opposite of what I need. I currently have some nasty inner query

Cursor.getType() for API Level <11

爱⌒轻易说出口 提交于 2019-11-28 09:41:12
I'm querying the CallLog content provider and need to detect the column types. In Honeycomb and newer (API Level 11+) you can get a columns preferred data type by calling the method Cursor.getType(int columnIndex) which returns one of the following types: FIELD_TYPE_NULL (0) FIELD_TYPE_INTEGER (1) FIELD_TYPE_FLOAT (2) FIELD_TYPE_STRING (3) FIELD_TYPE_BLOB (4) How can I accomplish this on pre-Honeycomb <11 devices? I've tried the following: for ( int i = 0; i < cursor.getColumnCount(); i++ ) { int columnType = -1; try { cursor.getInt( i ); columnType = Cursor.FIELD_TYPE_INTEGER; } catch (

How to represent 2 cursors as 1 sorted cursor?

て烟熏妆下的殇ゞ 提交于 2019-11-28 08:43:52
问题 I have 2 different sets of data, each of them use its own ContentProvider . Querying to them I can get 2 different cursors. Those 2 cursors has 2 different primary keys, but there's one and the same field ( DATE ) which I can use for ordering (other fields are different). My goal is to have one final merged Cursor which will be sorted by those DATE field. I have investigated MergeCursor but it doesn't fit to me, since it returns merged/concatenated (but not sorted Cursor ). Any ideas, clues?

How to disable cursor positioning and text selection in an EditText? (Android)

风格不统一 提交于 2019-11-28 07:14:55
I'm searching for a way to prevent the user from moving the cursor position anywhere. The cursor should always stay at the end of the current EditText value. In addition to that the user should not be able to select anything in the EditText. Do you have any idea how to realize that in Android using an EditText? To clarify: the user should be able to insert text, but only at the end. I had the same problem. This ended up working for me: public class CustomEditText extends EditText { @Override public void onSelectionChanged(int start, int end) { CharSequence text = getText(); if (text != null) {

Using String[] selectionArgs in SQLiteDatabase.query()

怎甘沉沦 提交于 2019-11-28 05:13:23
How do I use the String[] selectionArgs in SQLiteDatabase.query() ? I wish I could just set it to null , as I have no use for it. I am just trying to load an entire unsorted table from a database into a Cursor . Any suggestions on how to achieve this? selectionArgs replace any question marks in the selection string. for example: String[] args = { "first string", "second@string.com" }; Cursor cursor = db.query("TABLE_NAME", null, "name=? AND email=?", args, null); as for your question - you can use null Yes, you may set all parameters to null except the table name. for example: Cursor cursor =

how to load more than 1 MB data from sqlite db to android cursor?

主宰稳场 提交于 2019-11-28 00:20:02
问题 exactly i am trying to load more than 1MB of data from sqlite database to android cursor. At the time of loading it gives following error like 08-04 11:10:15.813: ERROR/CursorWindow(4465): need to grow: mSize = 2097152, size = 403719, freeSpace() = 209669, numRows = 1 08-04 11:10:15.813: ERROR/CursorWindow(4465): Attempting to grow window beyond max size (2097152) 08-04 11:10:15.813: ERROR/Cursor(4465): Failed allocating 403719 bytes for blob at 0,13 08-04 11:10:15.813: DEBUG/Cursor(4465):

Retrieve images of particular folder in Android

北城以北 提交于 2019-11-27 18:42:04
问题 In my application I created the GridView to show the image from particular folder. The issue is that I want to retrieve images from the DCIM/100ANDRO folder. Which type of arguments should be passed through query to retrieve such type of images? Please provide me solution. I am using following code to retrieve which gives me images captured by camera //importing only camera images and storing in ArrayList of class Images type String[] projection = { MediaStore.Images.Media._ID, MediaStore