Example usage for android.database Cursor getString

List of usage examples for android.database Cursor getString

Introduction

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

Prototype

String getString(int columnIndex);

Source Link

Document

Returns the value of the requested column as a String.

Usage

From source file:Main.java

public static String getRealPathFromURI(Context context, Uri contentURI) {
    String result = null;//from ww w. j a v a 2  s  .  com
    Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
        result = cursor.getString(idx);
        cursor.close();
    }
    return result;
}

From source file:Main.java

public static String getRealPathFromURI_BelowAPI11(Context context, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    String result = null;/*ww w  .  j a  v  a 2  s . com*/

    try {
        Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        result = cursor.getString(column_index);

    } catch (Exception e) {
        result = null;
    }
    return result;
}

From source file:com.contentful.vault.SqliteHelper.java

@SuppressWarnings("unchecked")
private static Asset assetFromCursor(Cursor cursor) {
    String remoteId = cursor.getString(resourceColumnIndex(REMOTE_ID));
    String url = cursor.getString(assetColumnIndex(Asset.Fields.URL));
    String mimeType = cursor.getString(assetColumnIndex(Asset.Fields.MIME_TYPE));
    String title = cursor.getString(assetColumnIndex(Asset.Fields.TITLE));
    String description = cursor.getString(assetColumnIndex(Asset.Fields.DESCRIPTION));
    HashMap<String, Object> fileMap = null;
    byte[] fileBlob = cursor.getBlob(assetColumnIndex(Asset.Fields.FILE));

    if (fileBlob != null && fileBlob.length > 0) {
        try {//from  ww w. j a  v  a2 s  . c  om
            fileMap = BlobUtils.fromBlob(HashMap.class, fileBlob);
        } catch (IOException e) {
            throw new RuntimeException("Failed while deserializing file map for asset '" + remoteId + "'.");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    return Asset.builder().setUrl(url).setMimeType(mimeType).setTitle(title).setDescription(description)
            .setFile(fileMap).build();
}

From source file:Main.java

public static String getApnPort(Context context) {
    Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
    c.moveToFirst();//w  ww  .ja v  a2  s .c  o m
    if (c.isAfterLast()) {
        c.close();
        return "80";
    }

    String port = null;
    port = c.getString(c.getColumnIndex(APN_PROP_PORT));
    if (port == null) {
        c.close();
        port = "80";
    }
    c.close();
    return port;
}

From source file:edu.mit.mobile.android.livingpostcards.data.Card.java

public static boolean isCollaborative(Cursor c) {
    return Card.PRIVACY_PUBLIC.equals(c.getString(c.getColumnIndexOrThrow(COL_PRIVACY)));
}

From source file:Main.java

public static String getVideoPath(Activity activity, Uri uri) {
    String[] projection = { MediaStore.Video.Media.DATA };
    Cursor cursor = activity.managedQuery(uri, projection, null, null, null);
    activity.startManagingCursor(cursor);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
    cursor.moveToFirst();/*w  w w  .j a va2 s.  co  m*/
    return cursor.getString(column_index);

}

From source file:Main.java

public static String getPath(Activity activity, Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = activity.managedQuery(uri, projection, null, null, null);
    activity.startManagingCursor(cursor);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();//  www .j  a va  2 s  .  c om
    return cursor.getString(column_index);

}

From source file:Main.java

public static String getGSFID(Context context) {
    String result;/*  ww  w  . jav a 2  s  .  c  om*/
    final Uri URI = Uri.parse("content://com.google.android.gsf.gservices");
    final String ID_KEY = "android_id";
    String[] params = { ID_KEY };
    Cursor c = context.getContentResolver().query(URI, null, null, params, null);
    if (c == null || !c.moveToFirst() || c.getColumnCount() < 2) {
        return null;
    } else {
        result = Long.toHexString(Long.parseLong(c.getString(1)));
    }
    c.close();
    return result;
}

From source file:Main.java

/**
 * Utils to get File path//from  w ww .  j ava 2s  .  c o  m
 * 
 * @param uri
 * @return
 */
public static String getPath(Context context, Uri uri) {
    String scheme = uri.getScheme();
    String s = null;
    if (scheme.equals("content")) {
        String[] projection = { MediaStore.Files.FileColumns.DATA };
        Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
        int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATA);
        cursor.moveToFirst();
        s = cursor.getString(columnIndex);
    } else if (scheme.equals("file")) {
        s = uri.getPath();
    }
    // Log.d("ActionManager", "URI:" + uri + " - S:" + s);
    return s;
}

From source file:Main.java

public static String getMessageCount(Context context, String id) {
    String res = null;/* w w w.  j  av a2  s .  c  o m*/
    try {
        final String[] projection = new String[] { "_id", "message_count" };
        Uri uri = Uri.parse("content://mms-sms/conversations?simple=true");
        Cursor query = context.getContentResolver().query(uri, projection, null, null, "date DESC");
        if (query != null) {
            boolean find = false;
            while (query.moveToNext() && !find) {
                if (query.getString(query.getColumnIndex("_id")).equals(id)) {
                    res = query.getString(query.getColumnIndex("message_count"));
                    //                        Log.v("getMessageCount", "find, nb_sms = "+res);
                    find = true;
                }
            }
            query.close();
        }
    } catch (Exception e) {
        //            Log.v("getMessageCount", "Erreur");
        e.printStackTrace();
    }
    return res;
}