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 double getDouble(Cursor cursor, String columnName) {
    return cursor.getDouble(cursor.getColumnIndexOrThrow(columnName));
}

From source file:Main.java

public static int getInt(Cursor cursor, String columnName) {
    return cursor.getInt(cursor.getColumnIndexOrThrow(columnName));
}

From source file:Main.java

private static String getImageAbsolutePath0(Activity act, Uri uri) {
    // can post image
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = act.managedQuery(uri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();/*w ww .j  av a 2 s. c o m*/

    return cursor.getString(column_index);
}

From source file:Main.java

/** converts image content URI to file path */
public static String resolveUri(Activity activity, Uri uri) {
    String[] projection = { Images.Media.DATA };
    Cursor cursor = activity.managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(Images.Media.DATA);
    cursor.moveToFirst();//from w w w  . j  a  va2 s . co  m
    return cursor.getString(column_index);
}

From source file:Main.java

public static String getRealImagePath(Activity activity, Uri uriPath) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = activity.getContentResolver().query(uriPath, proj, null, null, null);
    int index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();/*from   ww w . jav  a 2s.  c o m*/
    String path = cursor.getString(index);
    // path = path.substring(5);
    return path;
}

From source file:Main.java

public static String convertMediaUriToPath(Context context, Uri uri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();/*w w  w  .j av  a2  s . c  om*/
    String path = cursor.getString(column_index);
    cursor.close();
    return path;
}

From source file:Main.java

public static String getRealPathFromURI_BelowAPI11(Context context, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();/*from w w  w  .  j a  v a  2 s.co m*/
    return cursor.getString(column_index);
}

From source file:Main.java

public static String getAbsoluteImagePath(Activity paramActivity, Uri paramUri) {
    Cursor localCursor = paramActivity.managedQuery(paramUri, new String[] { "_data" }, null, null, null);
    int i = localCursor.getColumnIndexOrThrow("_data");
    localCursor.moveToFirst();//from   w w  w .  j  a  va 2s. c  o m
    return localCursor.getString(i);
}

From source file:Main.java

public static String getAbsoluteImagePath(Context context, Uri uri) {
    // can post image
    String[] proj = { Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(Media.DATA);
    cursor.moveToFirst();/*  w  ww.  j  a va 2s  .c  om*/
    String path = cursor.getString(column_index);
    cursor.close();
    return path;
}

From source file:Main.java

public static String getPath(Context context, Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();//from   w w  w  . j  a v  a2  s.  c  om
    String path = cursor.getString(column_index);
    cursor.close();
    return path;
}