List of usage examples for android.database Cursor close
void close();
From source file:com.maskyn.fileeditorpro.util.AccessStorageApi.java
public static String getName(Context context, Uri uri) { if (uri == null || uri.equals(Uri.EMPTY)) return ""; String fileName = ""; try {/*from ww w .ja va 2 s . c o m*/ String scheme = uri.getScheme(); if (scheme.equals("file")) { fileName = uri.getLastPathSegment(); } else if (scheme.equals("content")) { String[] proj = { MediaStore.Images.Media.DISPLAY_NAME }; Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null); if (cursor != null && cursor.getCount() != 0) { int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME); cursor.moveToFirst(); fileName = cursor.getString(columnIndex); } if (cursor != null) { cursor.close(); } } } catch (Exception ex) { return ""; } return fileName; }
From source file:sg.macbuntu.android.pushcontacts.SmsReceiver.java
private static String getNameFromPhoneNumber(Context context, String phone) { Cursor cursor = context.getContentResolver().query( Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, phone), new String[] { Contacts.Phones.NAME }, null, null, null); if (cursor != null) { try {/* w w w.ja v a 2 s.c om*/ if (cursor.getCount() > 0) { cursor.moveToFirst(); String name = cursor.getString(0); Log.e("PUSH_CONTACTS", "Pushed name: " + name); return name; } } finally { cursor.close(); } } return null; }
From source file:com.coinomi.wallet.ExchangeRatesProvider.java
@Nullable public static ExchangeRate getRate(final Context context, @Nonnull final String coinSymbol, @Nonnull String localSymbol) { ExchangeRate rate = null;//from w ww . ja v a 2 s.c o m if (context != null) { final Uri uri = contentUriToCrypto(context.getPackageName(), localSymbol, true); final Cursor cursor = context.getContentResolver().query(uri, null, ExchangeRatesProvider.KEY_CURRENCY_ID, new String[] { coinSymbol }, null); if (cursor != null) { if (cursor.moveToFirst()) { rate = getExchangeRate(cursor); } cursor.close(); } } return rate; }
From source file:Main.java
/** * Get the value of the data column for this Uri. This is useful for * MediaStore Uris, and other file-based ContentProviders. * * @param context/*from w w w . ja v a 2 s .co m*/ * The context. * @param uri * The Uri to query. * @param selection * (Optional) Filter used in the query. * @param selectionArgs * (Optional) Selection arguments used in the query. * @return The value of the _data column, which is typically a file path. * @author paulburke */ public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(column); return cursor.getString(column_index); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:com.binomed.showtime.android.util.localisation.LocationUtils.java
private static boolean checkSkyHookRegistration(Context context) { boolean result = false; CineShowtimeDbAdapter mDbHelper = new CineShowtimeDbAdapter(context); mDbHelper.open();/*from www.j ava2s .c o m*/ Cursor cursorRegistration = mDbHelper.fetchSkyHookRegistration(); if (cursorRegistration != null) { try { result = cursorRegistration.moveToFirst(); } finally { cursorRegistration.close(); if ((mDbHelper != null) && mDbHelper.isOpen()) { mDbHelper.close(); } } } return result; }
From source file:Main.java
public static String getAccountType(Context context, long id, String name) { try {/* w w w . j a v a 2 s .co m*/ Cursor cur = context.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, new String[] { ContactsContract.RawContacts.ACCOUNT_TYPE, ContactsContract.RawContacts.ACCOUNT_NAME }, ContactsContract.RawContacts.CONTACT_ID + " = ?", new String[] { String.valueOf(id) }, null); if (cur != null) { String str = ""; while (cur.moveToNext()) { str += cur.getString(cur.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE)); } // Log.v("getAccountType", name+" => "+str); cur.close(); Matcher m = accountTypePattern.matcher(str); String last = ""; while (m.find()) { last = m.group(1); } return last; } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:de.wikilab.android.friendica01.Max.java
public static String getRealPathFromURI(Context ctx, Uri contentUri) { Log.i("FileTypes", "URI = " + contentUri + ", scheme = " + contentUri.getScheme()); if (contentUri.getScheme().equals("file")) { return contentUri.getPath(); } else {/*from w w w . jav a2s . c o m*/ String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = ctx.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); String res = cursor.getString(column_index); cursor.close(); return res; } }
From source file:com.coinomi.wallet.ExchangeRatesProvider.java
public static List<ExchangeRate> getRates(final Context context, @Nonnull String localSymbol) { ImmutableList.Builder<ExchangeRate> builder = ImmutableList.builder(); if (context != null) { final Uri uri = contentUriToCrypto(context.getPackageName(), localSymbol, true); final Cursor cursor = context.getContentResolver().query(uri, null, null, new String[] { null }, null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst();//from w w w. j a v a 2 s. c o m do { builder.add(getExchangeRate(cursor)); } while (cursor.moveToNext()); cursor.close(); } } return builder.build(); }
From source file:net.kourlas.voipms_sms.Utils.java
/** * Gets the name of a contact from the Android contacts provider, given a phone number. * * @param applicationContext The application context. * @param phoneNumber The phone number of the contact. * @return the name of the contact.//from ww w . j av a 2s . c o m */ public static String getContactName(Context applicationContext, String phoneNumber) { Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor cursor = applicationContext.getContentResolver().query(uri, new String[] { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); if (cursor.moveToFirst()) { String name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)); cursor.close(); return name; } else { cursor.close(); return null; } }
From source file:com.deliciousdroid.platform.ContactManager.java
/** * Returns the RawContact id for a sample SyncAdapter contact, or 0 if the * sample SyncAdapter user isn't found./*from www. j a va 2 s. c om*/ * * @param context the Authenticator Activity context * @param userId the sample SyncAdapter user ID to lookup * @return the RawContact id, or 0 if not found */ private static List<Long> lookupAllContacts(ContentResolver resolver) { List<Long> result = new ArrayList<Long>(); final Cursor c = resolver.query(RawContacts.CONTENT_URI, AllUsersQuery.PROJECTION, AllUsersQuery.SELECTION, null, null); try { while (c.moveToNext()) { result.add(c.getLong(AllUsersQuery.COLUMN_ID)); } } finally { if (c != null) { c.close(); } } return result; }