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 File getFileFromUri(Uri uri, Activity activity) {
    String filePath = null;// w  w w.  j  av a  2 s.  c o  m
    String scheme = uri.getScheme();
    filePath = uri.getPath();
    if (filePath != null && scheme != null && scheme.equals("file")) {
        return new File(filePath);
    }

    String[] projection = { MediaStore.Images.ImageColumns.DATA };
    Cursor c = activity.managedQuery(uri, projection, null, null, null);
    if (c != null && c.moveToFirst()) {
        filePath = c.getString(0);
    }
    if (filePath != null) {
        return new File(filePath);
    }
    return null;

}

From source file:Main.java

public static String extractFilenameFromUri(Uri uri, Activity activity) {

    String fileName = null;//from w ww .  ja  va2  s .co  m
    if (uri == null) {
        throw new IllegalArgumentException();
    }
    String scheme = uri.getScheme();
    String path = uri.getPath();
    if (path != null && scheme != null && scheme.equals("file")) {
        fileName = path.substring(path.lastIndexOf("/") + 1);
    }

    String[] projection = { MediaStore.Images.ImageColumns.DISPLAY_NAME /* col1 */ };

    Cursor c = activity.managedQuery(uri, projection, null, null, null);
    if (c != null && c.moveToFirst()) {
        fileName = c.getString(0);
    }
    return fileName;
}

From source file:Main.java

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

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

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();
    }/*  ww w. ja  va 2s .c o  m*/
    return null;
}

From source file:Main.java

public static String getFileFromStorage(Context context, Intent data) {
    Uri pickedImage = data.getData();//from   w w  w  . j  a  va2s.  c  om
    String[] filePath = { MediaStore.Images.Media.DATA };
    String path = "";
    Cursor cursor = context.getContentResolver().query(pickedImage, filePath, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        path = cursor.getString(cursor.getColumnIndex(filePath[0]));
        cursor.close();
    }
    return path;
}

From source file:Main.java

public static String[] getTrailers(Cursor data) {
    List<String> lista = new ArrayList<String>();
    lista.add("Select Trailer");

    data.moveToFirst();/*from w ww. j a va 2 s  . c o m*/
    if (!data.getString(COL_TRAILER_KEY).equalsIgnoreCase("No Trailer Available")) {
        //loop through cursor to get all trailers
        for (int i = 1; i < data.getCount() + 1; i++) {
            if (!lista.contains(data.getString(COL_TRAILER_KEY))) {
                lista.add(data.getString(COL_TRAILER_KEY));
                data.moveToNext();
            } else {
                data.moveToNext();
            }
        }
    }

    String[] ltrailer;
    if (lista.size() < 1) {
        ltrailer = new String[1];
        ltrailer[0] = "No Trailer Available";
    } else {
        ltrailer = lista.toArray(new String[lista.size()]);
    }

    return ltrailer;
}

From source file:Main.java

/**
 * get the connection proxy and port//from  ww w  .  j  av a2  s . c o  m
 * @param context
 * @return
 */
public static String[] getHostAndProxy(Context context) {
    Uri uri = Uri.parse("content://telephony/carriers/preferapn");
    Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToNext();
        String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy"));
        String port = mCursor.getString(mCursor.getColumnIndex("port"));
        return new String[] { proxyStr, port };
    }
    return null;
}

From source file:Main.java

public static Map<String, Uri> getRingtones(Activity activity) {
    RingtoneManager manager = new RingtoneManager(activity);
    manager.setType(RingtoneManager.TYPE_RINGTONE);
    Cursor cursor = manager.getCursor();

    Map<String, Uri> list = new LinkedHashMap<>();
    while (cursor.moveToNext()) {
        String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
        Uri notificationUri = manager.getRingtoneUri(cursor.getPosition());

        list.put(notificationTitle, notificationUri);
    }/*from  w  w w .  jav a2 s. com*/

    return list;
}

From source file:Main.java

/**
 * get the sound list of the system/*from  w ww  .  j a va2s  . co m*/
 */
public static ArrayList<String> getSystemRingList(Context con) {
    ArrayList<String> getArray = new ArrayList<String>();
    ContentResolver cr = con.getContentResolver();
    String[] cols = new String[] { MediaStore.Audio.Media.IS_RINGTONE, MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.DISPLAY_NAME };
    Cursor cursor = cr.query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, cols, null, null, null);
    if (cursor.moveToFirst()) {
        do {
            if (cursor.getString(0).equals("1")) {
                getArray.add(cursor.getString(2));
            }

        } while (cursor.moveToNext());
    }
    return getArray;
}

From source file:Main.java

public static String query(Context context, Uri uri) {
    if (context == null || uri == null)
        return "";
    Cursor cursor = context.getContentResolver().query(uri,
            new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null);
    cursor.moveToNext();// www  .j  a v  a 2 s .  com
    return cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
}