Android Context Get getPath(Context context, Uri uri)

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

Description

get Path

License

Apache License

Declaration

public static String getPath(Context context, Uri uri)
            throws URISyntaxException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.URISyntaxException;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

public class Main {
    public static String getPath(Context context, Uri uri)
            throws URISyntaxException {
        if ("content".equalsIgnoreCase(uri.getScheme())) {
            String[] projection = { "_data" };
            Cursor cursor = null;

            try {
                cursor = context.getContentResolver().query(uri,
                        projection, null, null, null);
                int column_index = cursor.getColumnIndexOrThrow("_data");
                if (cursor.moveToFirst()) {
                    return cursor.getString(column_index);
                }//from   www .  j  ava  2s  . co m
            } catch (Exception e) {
                // Eat it
            }
        } else if ("file".equalsIgnoreCase(uri.getScheme())) {
            return uri.getPath();
        }

        return null;
    }
}

Related

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