Example usage for android.database Cursor getColumnIndexOrThrow

List of usage examples for android.database Cursor getColumnIndexOrThrow

Introduction

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

Prototype

int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;

Source Link

Document

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

Usage

From source file:Main.java

public static String uriToFilePath(Activity context, Uri uri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor actualimagecursor = context.managedQuery(uri, proj, null, null, null);
    int actualImageColumnIndex = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    actualimagecursor.moveToFirst();//  w ww .  j av  a  2s . co  m
    String imgPath = actualimagecursor.getString(actualImageColumnIndex);
    return imgPath;
}

From source file:Main.java

public static String getPathFromUrl(Activity context, Uri uri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor actualimagecursor = context.managedQuery(uri, proj, null, null, null);
    int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    actualimagecursor.moveToFirst();/*  ww w . ja  v a2  s . c om*/
    String img_path = actualimagecursor.getString(actual_image_column_index);
    return img_path;
}

From source file:Main.java

public static String getRealPathFromUriBelowApi11(Context context, Uri contentUri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(contentUri, projection, null, null, null);
    int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();/*from   w w  w  . j  a  v  a2s .c o m*/
    return cursor.getString(columnIndex);
}

From source file:Main.java

public static String getAbsolutePathFromUri(Context ctx, Uri contentUri) {
    String[] proj = { MediaStore.Video.Media.DATA };
    Cursor cursor = ctx.getContentResolver().query(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();/*from   w ww.ja  v  a  2  s. c  om*/
    return cursor.getString(column_index);
}

From source file:Main.java

@SuppressLint("NewApi")
public static String getRealPathFromURI_API11to18(Context context, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    String result = null;//from  www  .  j a  va  2  s  .  c  o  m

    CursorLoader cursorLoader = new CursorLoader(context, contentUri, proj, null, null, null);
    Cursor cursor = cursorLoader.loadInBackground();

    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        result = cursor.getString(column_index);
    }
    return result;
}

From source file:Main.java

@SuppressLint("NewApi")
public static String getRealPathFromUriApi11to18(Context context, Uri contentUri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    String result = null;//from  ww  w. ja  v  a2 s  .  c  o m

    CursorLoader cursorLoader = new CursorLoader(context, contentUri, projection, null, null, null);
    Cursor cursor = cursorLoader.loadInBackground();

    if (cursor != null) {
        int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        result = cursor.getString(columnIndex);
    }
    return result;
}

From source file:Main.java

public static String getPath(Context context, Uri uri) throws NullPointerException {
    final String[] projection = { MediaColumns.DATA };
    final Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
    final int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
    cursor.moveToFirst();/*from w w w  .j a  v a2  s.  com*/
    return cursor.getString(column_index);
}

From source file:Main.java

public static String getAbsoluteImagePath(Context context, Uri uri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
    cursor.moveToFirst();//  w  ww  .ja  va 2  s  .  c o m
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    return cursor.getString(column_index);
}

From source file:com.battlelancer.seriesguide.util.ShareUtils.java

public static String onCreateShareString(Context context, final Cursor episode) {
    int season = episode.getInt(episode.getColumnIndexOrThrow(Episodes.SEASON));
    int number = episode.getInt(episode.getColumnIndexOrThrow(Episodes.NUMBER));
    String title = episode.getString(episode.getColumnIndexOrThrow(Episodes.TITLE));
    return Utils.getNextEpisodeString(context, season, number, title);
}

From source file:Main.java

public static String getRealPathFromURI_BelowAPI11(Context context, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    String result = null;//from  w ww . j  a  va2s  .c  om

    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;
}