List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:com.chen.emailcommon.utility.AttachmentUtilities.java
/** * In support of deleting a message, find all attachments and delete associated cached * attachment files.//from w ww .j a v a 2 s . c o m * @param context * @param accountId the account for the message * @param messageId the message */ public static void deleteAllCachedAttachmentFiles(Context context, long accountId, long messageId) { final Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, messageId); final Cursor c = context.getContentResolver().query(uri, ATTACHMENT_CACHED_FILE_PROJECTION, null, null, null); try { while (c.moveToNext()) { final String fileName = c.getString(0); if (!TextUtils.isEmpty(fileName)) { final File cachedFile = new File(fileName); // Note, delete() throws no exceptions for basic FS errors (e.g. file not found) // it just returns false, which we ignore, and proceed to the next file. // This entire loop is best-effort only. cachedFile.delete(); } } } finally { c.close(); } }
From source file:com.energysystem.videoexplorerTV.video.VideoProvider.java
public static HashMap<String, List<Video>> buildMedia(String url, Cursor data) throws JSONException { mMovieList = new HashMap<String, List<Video>>(); mMovieList.clear();//ww w . j av a2 s . c o m Log.e("Abrimos", "Videos"); List<Video> categoryList = new ArrayList<Video>(); List<Video> categoryList2 = new ArrayList<Video>(); while (data.moveToNext()) { int videoID = data.getInt(data.getColumnIndex(MediaStore.Video.Media._ID)); int title = data.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE); int category = data.getColumnIndexOrThrow(MediaStore.Video.Media.CATEGORY); int durationID = data.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION); int data_string = data.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); //int videoUrl = data.getColumnIndexOrThrow(MediaStore.Video.Media.EXTERNAL_CONTENT_URI.toString()); // int bgImageUrl = data.getColumnIndexOrThrow(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI.toString()); int duration = Integer.parseInt(data.getString(durationID)); String categoria = new File(data.getString(data_string)).getParent(); Log.e("Ruta:", categoria); if (categoria.equals("/storage/emulated/0/Movies")) { categoryList.add(buildMovieInfo(categoria, data.getString(title), "Descripcion", String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration), TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID) .toString())); mMovieList.put("Almacenamiento Interno", categoryList); } else { categoryList2.add(buildMovieInfo(categoria, data.getString(title), "Descripcion", String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration), TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID) .toString())); mMovieList.put("USB", categoryList2); } } /*JSONObject jsonObj = new VideoProvider().parseUrl(url); JSONArray categories = jsonObj.getJSONArray(TAG_GOOGLE_VIDEOS); if (null != categories) { Log.d(TAG, "category #: " + categories.length()); String title; String videoUrl; String bgImageUrl; String cardImageUrl; String studio; for (int i = 0; i < categories.length(); i++) { JSONObject category = categories.getJSONObject(i); String category_name = category.getString(TAG_CATEGORY); JSONArray videos = category.getJSONArray(TAG_MEDIA); Log.d(TAG, "category: " + i + " Name:" + category_name + " video length: " + videos.length()); List<Video> categoryList = new ArrayList<Video>(); if (null != videos) { for (int j = 0; j < videos.length(); j++) { JSONObject video = videos.getJSONObject(j); String description = video.getString(TAG_DESCRIPTION); JSONArray videoUrls = video.getJSONArray(TAG_SOURCES); if (null == videoUrls || videoUrls.length() == 0) { continue; } title = video.getString(TAG_TITLE); videoUrl = getVideoPrefix(category_name, videoUrls.getString(0)); bgImageUrl = getThumbPrefix(category_name, title, video.getString(TAG_BACKGROUND)); cardImageUrl = getThumbPrefix(category_name, title, video.getString(TAG_CARD_THUMB)); studio = video.getString(TAG_STUDIO); categoryList.add(buildMovieInfo(category_name, title, description, studio, videoUrl, cardImageUrl, bgImageUrl)); } mMovieList.put(category_name, categoryList); } } }*/ Log.e("VideoProvider", "Tamano mMovie: " + mMovieList.size()); return mMovieList; }
From source file:com.csipsimple.backup.SipProfileJson.java
public static JSONArray serializeSipProfiles(Context ctxt) { JSONArray jsonSipProfiles = new JSONArray(); Cursor c = ctxt.getContentResolver().query(SipProfile.ACCOUNT_URI, DBProvider.ACCOUNT_FULL_PROJECTION, null, null, null);/*from w w w . java2s . com*/ if (c != null) { try { while (c.moveToNext()) { SipProfile account = new SipProfile(c); JSONObject p = serializeSipProfile(ctxt, account); try { jsonSipProfiles.put(jsonSipProfiles.length(), p); } catch (JSONException e) { Log.e(THIS_FILE, "Impossible to add profile", e); } } } catch (Exception e) { Log.e(THIS_FILE, "Error on looping over sip profiles", e); } finally { c.close(); } } // Add negative fake accounts Map<String, String> callHandlers = CallHandlerPlugin.getAvailableCallHandlers(ctxt); for (String packageName : callHandlers.keySet()) { final Long externalAccountId = CallHandlerPlugin.getAccountIdForCallHandler(ctxt, packageName); SipProfile gsmProfile = new SipProfile(); gsmProfile.id = externalAccountId; JSONObject p = serializeSipProfile(ctxt, gsmProfile); try { jsonSipProfiles.put(jsonSipProfiles.length(), p); } catch (JSONException e) { Log.e(THIS_FILE, "Impossible to add profile", e); } } return jsonSipProfiles; }
From source file:com.taobao.weex.devtools.inspector.protocol.module.Database.java
/** * Flatten all columns and all rows of a cursor to a single array. The array cannot be * interpreted meaningfully without the number of columns. * * @param cursor/*from ww w . j av a 2 s.c o m*/ * @param limit Maximum number of rows to process. * @return List of Java primitives matching the value type of each column, converted to * strings. */ private static ArrayList<String> flattenRows(Cursor cursor, int limit) { Util.throwIfNot(limit >= 0); ArrayList<String> flatList = new ArrayList<>(); final int numColumns = cursor.getColumnCount(); for (int row = 0; row < limit && cursor.moveToNext(); row++) { for (int column = 0; column < numColumns; column++) { switch (cursor.getType(column)) { case Cursor.FIELD_TYPE_NULL: flatList.add(null); break; case Cursor.FIELD_TYPE_INTEGER: flatList.add(String.valueOf(cursor.getLong(column))); break; case Cursor.FIELD_TYPE_FLOAT: flatList.add(String.valueOf(cursor.getDouble(column))); break; case Cursor.FIELD_TYPE_BLOB: flatList.add(blobToString(cursor.getBlob(column))); break; case Cursor.FIELD_TYPE_STRING: default: flatList.add(cursor.getString(column)); break; } } } if (!cursor.isAfterLast()) { for (int column = 0; column < numColumns; column++) { flatList.add("{truncated}"); } } return flatList; }
From source file:Main.java
public static Cursor getAllCallLogAboutACaller(Context context, String callerNumber) { // cancello la chiamata in uscita se nelle preferenze ? settata tale opzione Uri delUri = Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, ""); Cursor cursor = context.getContentResolver().query(delUri, null, android.provider.CallLog.Calls.NUMBER + "=?", new String[] { "404" }, null); try {/*ww w. j a va 2 s . co m*/ boolean moveToFirst = cursor.moveToFirst(); Log.i("MOVETOFIRST", "moveToFirst=" + moveToFirst); do { int numberColumn = cursor.getColumnIndex(android.provider.CallLog.Calls.NUMBER); String callerPhoneNumber = cursor.getString(numberColumn); Log.i(TAG, "numero : " + callerPhoneNumber); } while (cursor.moveToNext()); } catch (Exception e) { Log.e(TAG, "Problem moving to first entry", e); } return cursor; }
From source file:com.deliciousdroid.platform.ContactManager.java
private static String lookupUsername(ContentResolver resolver, long id) { String result = null;/*from w w w . j a va 2s . c o m*/ final Cursor c = resolver.query(RawContacts.CONTENT_URI, UsernameQuery.PROJECTION, UsernameQuery.SELECTION, new String[] { Long.toString(id) }, null); try { while (c.moveToNext()) { result = c.getString(UsernameQuery.COLUMN_ID); } } finally { if (c != null) { c.close(); } } return result; }
From source file:com.deliciousdroid.platform.ContactManager.java
private static long lookupHighWatermark(ContentResolver resolver, long id) { long result = 0; final Cursor c = resolver.query(RawContacts.CONTENT_URI, HighWatermarkQuery.PROJECTION, HighWatermarkQuery.SELECTION, new String[] { Long.toString(id) }, null); try {//w w w . j a v a 2 s . co m while (c.moveToNext()) { result = c.getLong(HighWatermarkQuery.COLUMN_ID); } } finally { if (c != null) { c.close(); } } return result; }
From source file:im.delight.android.baselib.Social.java
/** * Returns a list of phone numbers for the contact with the given lookup ID * * @param lookupID the lookup ID to get the phone numbers for * @param context Context instance to get the ContentResolver from * @return CharSequence[] containing all phone numbers for the given contact *//*from w ww.ja v a 2s. co m*/ public static CharSequence[] getContactPhone(String lookupID, Context context) { Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER }; String where = ContactsContract.Contacts.LOOKUP_KEY + " = ?"; String[] selectionArgs = new String[] { lookupID }; String sortOrder = null; Cursor result = context.getContentResolver().query(uri, projection, where, selectionArgs, sortOrder); String phone; if (result != null) { if (result.getCount() > 0) { CharSequence[] res = new CharSequence[result.getCount()]; int i = 0; while (result.moveToNext()) { phone = result.getString(result.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); if (phone != null) { res[i] = phone; i++; } } result.close(); return res; } else { result.close(); return null; } } else { return null; } }
From source file:im.delight.android.baselib.Social.java
/** * Returns a list of email addresses for the contact with the given lookup ID * * @param lookupID the lookup ID to get the email addresses for * @param context Context instance to get the ContentResolver from * @return CharSequence[] containing all email addresses for the given contact *//*from w w w . ja va2 s . c o m*/ public static CharSequence[] getContactEmail(String lookupID, Context context) { Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI; String[] projection = new String[] { ContactsContract.CommonDataKinds.Email.DATA }; String where = ContactsContract.Contacts.LOOKUP_KEY + " = ?"; String[] selectionArgs = new String[] { lookupID }; String sortOrder = null; Cursor result = context.getContentResolver().query(uri, projection, where, selectionArgs, sortOrder); String email; if (result != null) { if (result.getCount() > 0) { CharSequence[] res = new CharSequence[result.getCount()]; int i = 0; while (result.moveToNext()) { email = result.getString(result.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)); if (email != null) { res[i] = email; i++; } } result.close(); return res; } else { result.close(); return null; } } else { return null; } }
From source file:Main.java
public static LinkedHashMap<String, Uri> GetMatchedContactsList(Context context, String searchTerm) { LinkedHashMap<String, Uri> contactList = new LinkedHashMap<String, Uri>(); ContentResolver cr = context.getContentResolver(); String columns[] = { ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.PHOTO_THUMBNAIL_URI }; Cursor cur; if (searchTerm == null) { cur = cr.query(ContactsContract.Contacts.CONTENT_URI, columns, null, null, null); } else {//w w w. j a v a 2 s . c o m cur = cr.query(ContactsContract.Contacts.CONTENT_URI, columns, ContactsContract.Contacts.DISPLAY_NAME + " LIKE " + DatabaseUtils.sqlEscapeString("%" + searchTerm + "%"), null, ContactsContract.Contacts.DISPLAY_NAME + " ASC"); } if (cur != null) { if (cur.getCount() > 0) { while (cur.moveToNext()) { String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); String photoURI = cur .getString(cur.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI)); if (photoURI != null) { Uri thumbUri = Uri.parse(photoURI); contactList.put(name, thumbUri); } } } cur.close(); } return contactList; }