Android Context Get getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs)

Here you can find the source of getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs)

Description

Get the value of the data column for this Uri.

Parameter

Parameter Description
context The context.
uri The Uri to query.
selection (Optional) Filter used in the query.
selectionArgs (Optional) Selection arguments used in the query.

Return

The value of the _data column, which is typically a file path.

Declaration

public static String getDataColumn(Context context, Uri uri,
        String selection, String[] selectionArgs) 

Method Source Code

//package com.java2s;

import android.content.Context;

import android.database.Cursor;
import android.net.Uri;

public class Main {
    /**/*  w  ww .ja v a 2 s .c  om*/
     * Get the value of the data column for this Uri. This is useful for
     * MediaStore Uris, and other file-based ContentProviders.
     *
     * @param context       The context.
     * @param uri           The Uri to query.
     * @param selection     (Optional) Filter used in the query.
     * @param selectionArgs (Optional) Selection arguments used in the query.
     * @return The value of the _data column, which is typically a file path.
     */
    public static String getDataColumn(Context context, Uri uri,
            String selection, String[] selectionArgs) {

        Cursor cursor = null;
        final String column = "_data";
        final String[] projection = { column };

        try {
            cursor = context.getContentResolver().query(uri, projection,
                    selection, selectionArgs, null);
            if (cursor != null && cursor.moveToFirst()) {
                final int column_index = cursor
                        .getColumnIndexOrThrow(column);
                return cursor.getString(column_index);
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
        return null;
    }
}

Related

  1. getCurrentTimeString(Context aContext, long aDate)
  2. getCurrentTimeString(Context context)
  3. readRaw(Context ctx, int res_id)
  4. loadImageFromAsset(Context context, String id)
  5. hasTelephony(@Nonnull Context context)
  6. getPath(final Context context, final Uri uri)
  7. cachedJson(Context context, URI uri)
  8. cacheJson(Context context, URI uri, String jsonSource)
  9. getSharedPreferences(Context context)