Android Context Get getNameFromUri(Context context, Uri uri)

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

Description

get Name From Uri

License

Open Source License

Declaration

public static String getNameFromUri(Context context, Uri uri) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;

import android.database.Cursor;

import android.net.Uri;

import android.provider.OpenableColumns;

import java.io.File;

public class Main {
    public static String getNameFromUri(Context context, Uri uri) {
        if (uri.getScheme().equals("file")) {
            return new File(uri.getPath()).getName();
        } else if (uri.getScheme().equals("content")) {
            Cursor cursor = context.getContentResolver().query(uri, null,
                    null, null, null, null);

            try {
                if (cursor != null && cursor.moveToFirst()) {
                    return cursor.getString(cursor
                            .getColumnIndex(OpenableColumns.DISPLAY_NAME));
                }//from  w  w w  .j  a  v a  2  s .c om
            } finally {
                cursor.close();
            }
        }

        return null;
    }
}

Related

  1. getMemoryClass(Context context)
  2. getMinFontSize(Context context)
  3. getMobilityPackageInfo(Context context)
  4. getMobilityVersion(Context context)
  5. getMusesAppContext()
  6. getOffset(Context context)
  7. getOpenGLESVersion(final Context context)
  8. getOrientation(Context context, Uri photoUri)
  9. getPackageName(final Context context)