List of usage examples for android.database Cursor getString
String getString(int columnIndex);
From source file:Main.java
public static File getFromMediaUri(ContentResolver resolver, Uri uri) { if (uri == null) return null; if ("file".equals(uri.getScheme())) { return new File(uri.getPath()); } else if ("content".equals(uri.getScheme())) { final String[] filePathColumn = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DISPLAY_NAME }; Cursor cursor = null; try {// w ww.j a v a 2s . c om cursor = resolver.query(uri, filePathColumn, null, null, null); if (cursor != null && cursor.moveToFirst()) { final int columnIndex = (uri.toString().startsWith("content://com.google.android.gallery3d")) ? cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME) : cursor.getColumnIndex(MediaStore.MediaColumns.DATA); if (columnIndex != -1) { String filePath = cursor.getString(columnIndex); if (!TextUtils.isEmpty(filePath)) { return new File(filePath); } } } } catch (SecurityException ignored) { } finally { if (cursor != null) cursor.close(); } } return null; }
From source file:Main.java
public static boolean haveCalendars(Activity ctx) { boolean exists = false; String[] projection = new String[] { "_id", "name" }; Uri calendars = Uri.parse("content://calendar/calendars"); // Calendar uri changes for 2.2 Uri calendars_2_2 = Uri.parse("content://com.android.calendar/calendars"); Cursor managedCursor = ctx.managedQuery(calendars, projection, null, null, null); if (managedCursor == null || managedCursor.getCount() == 0) managedCursor = ctx.managedQuery(calendars_2_2, projection, null, null, null); if (managedCursor != null && managedCursor.moveToFirst()) { String calName;/*w w w. j av a 2 s . c o m*/ String calId; int nameColumn = managedCursor.getColumnIndex("name"); int idColumn = managedCursor.getColumnIndex("_id"); do { calName = managedCursor.getString(nameColumn); calId = managedCursor.getString(idColumn); exists = true; } while (managedCursor.moveToNext()); managedCursor.close(); } return exists; }
From source file:com.android.emailcommon.utility.AttachmentUtilities.java
/** * Resolve attachment id to content URI. Returns the resolved content URI (from the attachment * DB) or, if not found, simply returns the incoming value. * * @param attachmentUri//from w w w .j a v a 2 s .c o m * @return resolved content URI * * TODO: Throws an SQLite exception on a missing DB file (e.g. unknown URI) instead of just * returning the incoming uri, as it should. */ public static Uri resolveAttachmentIdToContentUri(ContentResolver resolver, Uri attachmentUri) { Cursor c = resolver.query(attachmentUri, new String[] { Columns.DATA }, null, null, null); if (c != null) { try { if (c.moveToFirst()) { final String strUri = c.getString(0); if (strUri != null) { return Uri.parse(strUri); } } } finally { c.close(); } } return attachmentUri; }
From source file:net.ccghe.emocha.model.DBAdapter.java
public static ArrayList<String> getFilePaths() { Cursor c = sDB.query(TABLE_DOWNLOADS, new String[] { "path" }, null, null, null, null, null); ArrayList<String> result = new ArrayList<String>(); int numRows = c.getCount(); for (int i = 0; i < numRows; i++) { c.moveToPosition(i);/*from ww w . ja v a2 s. c o m*/ result.add(c.getString(DL_COL_PATH)); } c.close(); return result; }
From source file:com.ppshein.PlanetMyanmarDictionary.common.java
public static void addBookmark(String notedword, Context context) { try {/*from w w w .j a v a2 s. c o m*/ DatabaseUtil dbUtil = new DatabaseUtil(context); dbUtil.open(); Cursor cursor = dbUtil.fetchBookmark(notedword); String getReturn = cursor.getString(1); cursor.close(); dbUtil.close(); Log.v("Existing Bookmarks", getReturn); } catch (Exception e) { DatabaseUtil dbUtil = new DatabaseUtil(context); dbUtil.open(); dbUtil.insertBookmark(notedword); dbUtil.close(); Toast toast = Toast.makeText(context, "Successfully bookmarked", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } }
From source file:net.ccghe.emocha.model.DBAdapter.java
public static ArrayList<String> getFilesFiltered(String filter) { ArrayList<String> result = new ArrayList<String>(); Cursor c = sDB.query(TABLE_DOWNLOADS, new String[] { "path" }, filter, null, null, null, null); int numRows = c.getCount(); Log.i(Constants.LOG_TAG, filter + " : " + numRows); for (int i = 0; i < numRows; i++) { c.moveToPosition(i);/*from w w w. java2 s. co m*/ result.add(c.getString(DL_COL_PATH)); Log.i(Constants.LOG_TAG, i + " : " + c.getString(DL_COL_PATH)); } c.close(); return result; }
From source file:com.ppshein.PlanetMyanmarDictionary.common.java
public static String checkBookmark(String notedword, Context context) { String returnString = "nofade"; try {/*from w w w . j a va 2 s . co m*/ DatabaseUtil dbUtil = new DatabaseUtil(context); dbUtil.open(); Cursor cursor = dbUtil.fetchBookmark(notedword); String getBookmark = cursor.getString(1); cursor.close(); dbUtil.close(); if (getBookmark.toString() != "") { returnString = "fade"; } } catch (Exception e) { returnString = "nofade"; } return returnString; }
From source file:Main.java
public static List<String> getAllNumbers(Activity callingActivity) { List<String> allNumbers = new ArrayList<String>(); Cursor managedCursor = callingActivity.managedQuery(CallLog.Calls.CONTENT_URI, null, null, null, null); int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER); int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE); int date = managedCursor.getColumnIndex(CallLog.Calls.DATE); int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION); StringBuilder sb = new StringBuilder(); sb.append("Call Details :"); while (managedCursor.moveToNext()) { String phNumber = managedCursor.getString(number); String callType = managedCursor.getString(type); String callDate = managedCursor.getString(date); Date callDayTime = new Date(Long.valueOf(callDate)); String callDuration = managedCursor.getString(duration); String dir = null;/*from w ww. j ava 2 s .c o m*/ if (!allNumbers.contains(phNumber)) { allNumbers.add(phNumber); } int dircode = Integer.parseInt(callType); switch (dircode) { case CallLog.Calls.OUTGOING_TYPE: dir = "OUTGOING"; break; case CallLog.Calls.INCOMING_TYPE: dir = "INCOMING"; break; case CallLog.Calls.MISSED_TYPE: dir = "MISSED"; break; } sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- " + dir + " \nCall Date:--- " + callDayTime + " \nCall duration in sec :--- " + callDuration); sb.append("\n----------------------------------"); // Log.i("getAllNumbers", sb.toString()); } managedCursor.close(); return allNumbers; }
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.// www . j a va 2 s .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.ppshein.PlanetMyanmarDictionary.common.java
public static String ProcessBookmark(String notedword, Context context) { String returnString = "nofade"; try {/* ww w . ja v a 2 s. c o m*/ DatabaseUtil dbUtil = new DatabaseUtil(context); dbUtil.open(); Cursor cursor = dbUtil.fetchBookmark(notedword); String getBookmark = cursor.getString(1); cursor.close(); dbUtil.close(); if (getBookmark.toString() != "") { dbUtil.open(); boolean IsDeleted = dbUtil.deleteBookmark(notedword); Log.v("Bookmarks", "Bookmark is deleted " + IsDeleted); dbUtil.close(); returnString = "nofade"; } } catch (Exception e) { addBookmark(notedword, context); returnString = "fade"; } return returnString; }