Android Context Get getPathFromUri(Context context, Uri uri)

Here you can find the source of getPathFromUri(Context context, Uri uri)

Description

get Path From Uri

License

Apache License

Parameter

Parameter Description
context a parameter
uri a parameter

Declaration

public static String getPathFromUri(Context context, Uri uri) 

Method Source Code

//package com.java2s;
/**/*from   www. j  a  v a  2 s.  co m*/
 * Copyright (c) 2013-2014, Rinc Liu (http://rincliu.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import android.content.Context;
import android.database.Cursor;

import android.net.Uri;
import android.provider.MediaStore;

public class Main {
    /**
     * @param context
     * @param uri
     * @return
     */
    public static String getPathFromUri(Context context, Uri uri) {
        String path = null;
        String[] proj = { MediaStore.Images.Media.DATA };
        Cursor cursor = context.getContentResolver().query(uri, proj, null,
                null, null);
        if (cursor != null && cursor.getCount() > 0
                && cursor.getColumnCount() > 0) {
            int column_index = -1;
            try {
                column_index = cursor
                        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
                cursor.close();
            }
            if (column_index != -1) {
                cursor.moveToFirst();
                path = cursor.getString(column_index);
            }
            cursor.close();
        }
        return path;
    }
}

Related

  1. getOrientation(Context context, Uri photoUri)
  2. getPackageName(final Context context)
  3. getPackageVersion(Context c)
  4. getPackageVersionAsInt(Context c)
  5. getPath(Context context, Uri uri)
  6. getPermissionLabel(Context context, String permission)
  7. getPreferences(Context context, String campaignUrn)
  8. getPrefs(Context context)
  9. getRealPathFromURI(Context context, Uri contentUri)