Example usage for android.database Cursor getColumnIndex

List of usage examples for android.database Cursor getColumnIndex

Introduction

In this page you can find the example usage for android.database Cursor getColumnIndex.

Prototype

int getColumnIndex(String columnName);

Source Link

Document

Returns the zero-based index for the given column name, or -1 if the column doesn't exist.

Usage

From source file:Main.java

public static String query(Context context, Uri uri) {
    Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null,
            null);/* ww w. j  av a2 s  .c o  m*/
    cursor.moveToNext();
    return cursor.getString(cursor.getColumnIndex(ImageColumns.DATA));
}

From source file:Main.java

public static String query(Context context, Uri uri) {
    Cursor cursor = context.getContentResolver().query(uri, new String[] { MediaColumns.DATA }, null, null,
            null);/*from  w  ww.j  ava  2 s  .c om*/
    cursor.moveToNext();
    return cursor.getString(cursor.getColumnIndex(MediaColumns.DATA));
}

From source file:br.com.bea.androidtools.api.model.EntityUtils.java

public static final Object convert(final Field field, final Cursor cursor) throws Exception {
    if (field.getType().equals(Long.class))
        return cursor.getLong(cursor.getColumnIndex(field.getAnnotation(Column.class).name()));
    if (field.getType().equals(Integer.class))
        return cursor.getInt(cursor.getColumnIndex(field.getAnnotation(Column.class).name()));
    if (field.getType().equals(Date.class))
        return DATE_FORMAT
                .parse(cursor.getString(cursor.getColumnIndex(field.getAnnotation(Column.class).name())));
    return cursor.getString(cursor.getColumnIndex(field.getAnnotation(Column.class).name()));
}

From source file:Main.java

public static ArrayList<String> cursorToArrayList(Cursor cursor) {
    ArrayList<String> list = new ArrayList<String>();
    cursor.moveToFirst();/*from   w  w  w  .j a v  a2  s .  co  m*/

    while (cursor.isAfterLast() == false) {
        list.add(cursor.getString(cursor.getColumnIndex("name")));
        cursor.moveToNext();
    }
    return list;
}

From source file:Main.java

public static float getFloatFromCursor(Cursor cursor, String columnName) {
    float value = -1;
    if (cursor != null && cursor.getPosition() >= 0 && cursor.getPosition() < cursor.getCount()) {
        int columnIndex = cursor.getColumnIndex(columnName);
        if (columnIndex >= 0) {
            value = cursor.getFloat(columnIndex);
        }// w ww.  ja  v  a  2 s .  c  o  m
    }
    return value;
}

From source file:Main.java

public static String getVideoPath(Context context, Intent data) {
    Cursor cursor = context.getContentResolver().query(data.getData(), null, null, null, null);
    if (cursor != null && cursor.moveToNext()) {
        String filePath = cursor.getString(cursor.getColumnIndex(VideoColumns.DATA));
        return filePath;
    } else if (data != null && data.getData() != null) {
        return data.getData().getEncodedPath();
    }// w  ww  . j  a  va 2s .c om
    return null;
}

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;/*w w  w . j  av  a  2s  .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:Main.java

private static Set<Integer> getAllAvailableProtocolVersions(Context context) {
    ContentResolver contentResolver = context.getContentResolver();
    Set<Integer> allAvailableVersions = new HashSet<Integer>();
    Uri uri = Uri.parse("content://appsneva.facebook.orca.provider.MessengerPlatformProvider/versions");
    String[] projection = new String[] { "version" };
    Cursor c = contentResolver.query(uri, projection, null, null, null);
    if (c != null) {
        try {//from  w w  w  . j  a  v  a  2  s.  co m
            int versionColumnIndex = c.getColumnIndex("version");
            while (c.moveToNext()) {
                int version = c.getInt(versionColumnIndex);
                allAvailableVersions.add(version);
            }
        } finally {
            c.close();
        }
    }
    return allAvailableVersions;
}

From source file:Main.java

private static Set<Integer> getAllAvailableProtocolVersions(Context context) {
    ContentResolver contentResolver = context.getContentResolver();
    Set<Integer> allAvailableVersions = new HashSet<Integer>();
    Uri uri = Uri.parse("content://com.facebook.orca.provider.MessengerPlatformProvider/versions");
    String[] projection = new String[] { "version" };
    Cursor c = contentResolver.query(uri, projection, null, null, null);
    if (c != null) {
        try {/*from w  ww  . ja  v a2 s .c om*/
            int versionColumnIndex = c.getColumnIndex("version");
            while (c.moveToNext()) {
                int version = c.getInt(versionColumnIndex);
                allAvailableVersions.add(version);
            }
        } finally {
            c.close();
        }
    }
    return allAvailableVersions;
}

From source file:Main.java

private static ArrayList<String> getNumbers(Context context) {
    ArrayList<String> list = new ArrayList<String>();
    Cursor cursor = null;
    try {//from w w w.  j  a v a2 s. c  o m
        cursor = context.getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);
        int phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);
        cursor.moveToFirst();
        do {
            String phoneNumber = cursor.getString(phoneNumberIdx);
            list.add(phoneNumber);
        } while (cursor.moveToNext());
    } catch (Exception e) {
        Log.d(context.getPackageName(), e.toString());
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    return list;
}