Example usage for android.net Uri getPath

List of usage examples for android.net Uri getPath

Introduction

In this page you can find the example usage for android.net Uri getPath.

Prototype

@Nullable
public abstract String getPath();

Source Link

Document

Gets the decoded path.

Usage

From source file:cn.ucai.yizhesale.activity.ChatActivity.java

/**
 * ?uri??//  ww w . j a v  a  2s  .  c  o m
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
    String st8 = getResources().getString(cn.ucai.yizhesale.R.string.cant_find_pictures);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        sendPicture(picturePath);
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        sendPicture(file.getAbsolutePath());
    }

}

From source file:com.dmsl.anyplace.UnifiedNavigationActivity.java

private void handleIntent(Intent intent) {

    String action = intent.getAction();
    if (Intent.ACTION_SEARCH.equals(action)) {

        // check what type of search we need
        SearchTypes searchType = AnyPlaceSeachingHelper.getSearchType(mMap.getCameraPosition().zoom);
        String query = intent.getStringExtra(SearchManager.QUERY);
        GeoPoint gp = userData.getLatestUserPosition();

        // manually launch the real search activity
        Intent searchIntent = new Intent(UnifiedNavigationActivity.this, SearchPOIActivity.class);
        // add query to the Intent Extras
        searchIntent.setAction(action);/* www  . jav a  2  s .co m*/
        searchIntent.putExtra("searchType", searchType);
        searchIntent.putExtra("query", query);
        searchIntent.putExtra("lat", (gp == null) ? csLat : gp.dlat);
        searchIntent.putExtra("lng", (gp == null) ? csLon : gp.dlon);
        startActivityForResult(searchIntent, SEARCH_POI_ACTIVITY_RESULT);

    } else if (Intent.ACTION_VIEW.equals(action)) {
        String data = intent.getDataString();

        if (data != null && data.startsWith("http")) {
            final Uri uri = intent.getData();
            if (uri != null) {
                String path = uri.getPath();

                if (path != null && path.equals("/getnavigation")) {
                    String poid = uri.getQueryParameter("poid");
                    if (poid == null || poid.equals("")) {
                        // Share building
                        // http://anyplace.rayzit.com/getnavigation?buid=username_1373876832005&floor=0
                        String buid = uri.getQueryParameter("buid");
                        if (buid == null || buid.equals("")) {
                            Toast.makeText(getBaseContext(), "Buid parameter expected", Toast.LENGTH_SHORT)
                                    .show();
                        } else {
                            mAutomaticGPSBuildingSelection = false;
                            mAnyplaceCache.loadBuilding(buid, new FetchBuildingTaskListener() {

                                @Override
                                public void onSuccess(String result, final BuildingModel b) {

                                    bypassSelectBuildingActivity(b, uri.getQueryParameter("floor"), true);

                                }

                                @Override
                                public void onErrorOrCancel(String result) {
                                    Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show();

                                }
                            }, UnifiedNavigationActivity.this);
                        }
                    } else {
                        // Share POI
                        // http://anyplace.rayzit.com/getnavigation?poid=username_username_1373876832005_0_35.14424091022549_33.41139659285545_1382635428093
                        mAutomaticGPSBuildingSelection = false;
                        new FetchPoiByPuidTask(new FetchPoiByPuidTask.FetchPoiListener() {

                            @Override
                            public void onSuccess(String result, final PoisModel poi) {

                                if (userData.getSelectedBuildingId() != null
                                        && userData.getSelectedBuildingId().equals(poi.buid)) {
                                    // Building is Loaded
                                    startNavigationTask(poi.puid);
                                } else {
                                    // Load Building
                                    mAnyplaceCache.loadBuilding(poi.buid, new FetchBuildingTaskListener() {

                                        @Override
                                        public void onSuccess(String result, final BuildingModel b) {

                                            bypassSelectBuildingActivity(b, poi.floor_number, true, poi);

                                        }

                                        @Override
                                        public void onErrorOrCancel(String result) {
                                            Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show();

                                        }
                                    }, UnifiedNavigationActivity.this);
                                }
                            }

                            @Override
                            public void onErrorOrCancel(String result) {
                                Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show();
                            }
                        }, this, poid).execute();
                    }
                }
            }
        } else {

            // Search TextBox results only

            // PoisModel or Place Class
            IPoisClass place_selected = AnyPlaceSeachingHelper.getClassfromJson(data);

            if (place_selected.id() != null) {
                // hide the search view when a navigation route is drawn
                if (searchView != null) {
                    searchView.setIconified(true);
                    searchView.clearFocus();
                }
                handleSearchPlaceSelection(place_selected);
            }

        }

    }
}

From source file:cmu.cconfs.instantMessage.activities.ChatActivity.java

/**
 * ?uri??/*from  w  ww  . j a va  2s  . c  o m*/
 *
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
    String st8 = getResources().getString(R.string.cant_find_pictures);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        sendPicture(picturePath);
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        sendPicture(file.getAbsolutePath());
    }

}

From source file:cn.gen.superwechat.activity.ChatActivity.java

/**
 * ?uri??//w w w  .  j a v a 2 s. c  om
 * 
 * @param selectedImage
 */
private void sendPicByUri(Uri selectedImage) {
    String[] filePathColumn = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
    String st8 = getResources().getString(cn.gen.superwechat.R.string.cant_find_pictures);
    if (cursor != null) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        cursor = null;

        if (picturePath == null || picturePath.equals("null")) {
            Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;
        }
        sendPicture(picturePath);
    } else {
        File file = new File(selectedImage.getPath());
        if (!file.exists()) {
            Toast toast = Toast.makeText(this, st8, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return;

        }
        sendPicture(file.getAbsolutePath());
    }

}

From source file:com.fullteem.yueba.app.ui.ChatActivity.java

/**
 * ??//from   w w w  . java2s  . c  o  m
 * 
 * @param uri
 */
private void sendFile(Uri uri) {
    String filePath = null;
    if ("content".equalsIgnoreCase(uri.getScheme())) {
        String[] projection = { "_data" };
        Cursor cursor = null;

        try {
            cursor = getContentResolver().query(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow("_data");
            if (cursor.moveToFirst()) {
                filePath = cursor.getString(column_index);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        filePath = uri.getPath();
    }
    File file = new File(filePath);
    if (file == null || !file.exists()) {
        Toast.makeText(getApplicationContext(), "?", 0).show();
        return;
    }
    if (file.length() > 10 * 1024 * 1024) {
        Toast.makeText(getApplicationContext(), "?10M", 0).show();
        return;
    }

    // ?
    EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE);
    // ?chattype,??
    if (chatType == CHATTYPE_GROUP)
        message.setChatType(ChatType.GroupChat);

    message.setReceipt(toChatUsername);
    // add message body
    NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath));
    message.addBody(body);
    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.refresh();
    listView.setSelection(listView.getCount() - 1);
    setResult(RESULT_OK);
}

From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java

public String getFileNameByUri(Context context, Uri uri) {
    String fileName = "unknown";// default fileName
    Uri filePathUri = uri;
    if (uri.getScheme().toString().compareTo("content") == 0) {
        ParcelFileDescriptor parcelFileDescriptor;
        String filename = null;//from   w w w.  jav a  2  s.co m
        try {
            FileOutputStream fos = null;
            parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r");
            FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
            Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
            String extr = Environment.getExternalStorageDirectory().toString();
            File mFolder = new File(extr + "/CHURCH");
            if (!mFolder.exists()) {
                mFolder.mkdir();
            } else {
                mFolder.delete();
                mFolder.mkdir();
            }

            String s = "rough.png";

            File f = new File(mFolder.getAbsolutePath(), s);

            filename = f.getAbsolutePath();
            Log.d("f", filename);
            try {
                fos = new FileOutputStream(f);
                image.compress(Bitmap.CompressFormat.PNG, 100, fos);
                fos.flush();
                fos.close();
            } catch (FileNotFoundException e) {

                e.printStackTrace();
            } catch (Exception e) {

                e.printStackTrace();
            }
            parcelFileDescriptor.close();
            return filename;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else if (uri.getScheme().compareTo("file") == 0) {
        fileName = filePathUri.getPath();
        File fill = new File(fileName);
        if (fill.exists()) {
            Log.d("exitst", "exist");
            ParcelFileDescriptor parcelFileDescriptor;
            String filename = null;
            FileOutputStream fos = null;
            Bitmap image = BitmapFactory.decodeFile(fileName);
            String extr = Environment.getExternalStorageDirectory().toString();
            File mFolder = new File(extr + "/CHURCH");
            if (!mFolder.exists()) {
                mFolder.mkdir();
            } else {
                mFolder.delete();
                mFolder.mkdir();
            }

            String s = "rough.png";

            File f = new File(mFolder.getAbsolutePath(), s);

            filename = f.getAbsolutePath();
            Log.d("f", filename);
            try {
                fos = new FileOutputStream(f);
                image.compress(Bitmap.CompressFormat.PNG, 100, fos);
                fos.flush();
                fos.close();
            } catch (FileNotFoundException e) {

                e.printStackTrace();
            } catch (Exception e) {

                e.printStackTrace();
            }
        } else {
            Log.d("not file exitst", "not exist");
        }
        Log.d("file", "file");
    } else {
        fileName = filePathUri.getPath();
        Log.d("else", "else");
    }

    return fileName;

}

From source file:com.oakesville.mythling.MediaActivity.java

protected void downloadItem(final Item item) {
    try {//w w w. j  ava  2s  . c  o  m
        final URL baseUrl = getAppSettings().getMythTvServicesBaseUrlWithCredentials();

        String fileUrl = baseUrl + "/Content/GetFile?";
        if (item.getStorageGroup() == null)
            fileUrl += "StorageGroup=None&";
        else
            fileUrl += "StorageGroup=" + item.getStorageGroup().getName() + "&";
        fileUrl += "FileName=" + URLEncoder.encode(item.getFilePath(), "UTF-8");

        Uri uri = Uri.parse(fileUrl.toString());
        ProxyInfo proxyInfo = MediaStreamProxy.needsAuthProxy(uri);
        if (proxyInfo != null) {
            // needs proxying to support authentication since DownloadManager doesn't support
            MediaStreamProxy proxy = new MediaStreamProxy(proxyInfo,
                    AuthType.valueOf(appSettings.getMythTvServicesAuthType()));
            proxy.init();
            proxy.start();
            fileUrl = "http://" + proxy.getLocalhost().getHostAddress() + ":" + proxy.getPort() + uri.getPath();
            if (uri.getQuery() != null)
                fileUrl += "?" + uri.getQuery();
        }

        Log.i(TAG, "Media download URL: " + fileUrl);

        stopProgress();

        DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
        Request request = new Request(Uri.parse(fileUrl));
        request.setTitle(item.getOneLineTitle());
        String downloadFilePath = null;
        try {
            if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                File downloadDir = Environment
                        .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                if (downloadDir.exists()) {
                    String downloadPath = AppSettings.getExternalStorageDir() + "/";
                    if (getPath() != null && !getPath().isEmpty() && !getPath().equals("/"))
                        downloadPath += getPath() + "/";
                    File destDir = new File(downloadDir + "/" + downloadPath);
                    if (destDir.isDirectory() || destDir.mkdirs()) {
                        downloadFilePath = downloadPath + item.getDownloadFilename();
                        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
                                downloadFilePath);
                        request.allowScanningByMediaScanner();
                    }
                }
            }
        } catch (IllegalStateException ex) {
            // store internal
        } catch (Exception ex) {
            // log, report and store internal
            Log.e(TAG, ex.getMessage(), ex);
            if (getAppSettings().isErrorReportingEnabled())
                new Reporter(ex).send();
            Toast.makeText(getApplicationContext(), getString(R.string.error_) + ex.toString(),
                    Toast.LENGTH_LONG).show();
        }
        long downloadId = dm.enqueue(request);
        registerDownloadReceiver(item, downloadId);
        Toast.makeText(getApplicationContext(), getString(R.string.downloading_) + item.getOneLineTitle(),
                Toast.LENGTH_LONG).show();
        getAppData().addDownload(new Download(item.getId(), downloadId, downloadFilePath, new Date()));
        if (item.isRecording() && (mediaList.isMythTv28() || getAppSettings().isMythlingMediaServices()))
            new GetCutListTask((Recording) item, downloadId).execute();
    } catch (Exception ex) {
        stopProgress();
        Log.e(TAG, ex.getMessage(), ex);
        if (getAppSettings().isErrorReportingEnabled())
            new Reporter(ex).send();
        Toast.makeText(getApplicationContext(), getString(R.string.error_) + ex.toString(), Toast.LENGTH_LONG)
                .show();
    }
}

From source file:com.applozic.mobicommons.file.FileUtils.java

/**
 * Get a file path from a Uri. This will get the the path for Storage Access
 * Framework Documents, as well as the _data field for the MediaStore and
 * other file-based ContentProviders.<br>
 * <br>//from w w  w.  j a  v a2s .  co m
 * Callers should check whether the path is local before assuming it
 * represents a local file.
 *
 * @param context The context.
 * @param uri     The Uri to query.
 * @author paulburke
 * @see #isLocal(String)
 * @see #getFile(android.content.Context, android.net.Uri)
 */

public static String getPath(final Context context, final Uri uri) {

    if (DEBUG)
        Log.d(TAG + " File -",
                "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: "
                        + uri.getPort() + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme()
                        + ", Host: " + uri.getHost() + ", Segments: " + uri.getPathSegments().toString());

    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        // LocalStorageProvider
        if (isLocalStorageDocument(uri)) {
            // The path is the id
            return DocumentsContract.getDocumentId(uri);
        }
        // ExternalStorageProvider
        else if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }

            // TODO handle non-primary volumes
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };

            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();

        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:com.maskyn.fileeditorpro.activity.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_FILE_CODE) {

            final Uri data = intent.getData();
            final GreatUri newUri = new GreatUri(data, AccessStorageApi.getPath(this, data),
                    AccessStorageApi.getName(this, data));

            newFileToOpen(newUri, "");
        } else if (requestCode == SELECT_FOLDER_CODE) {
            FileFilter fileFilter = new FileFilter() {
                public boolean accept(File file) {
                    return file.isFile();
                }/*from  w  w w .j  a v  a  2 s .  co m*/
            };
            final Uri data = intent.getData();
            File dir = new File(data.getPath());
            File[] fileList = dir.listFiles(fileFilter);
            for (int i = 0; i < fileList.length; i++) {
                Uri particularUri = Uri.parse("file://" + fileList[i].getPath());
                final GreatUri newUri = new GreatUri(particularUri,
                        AccessStorageApi.getPath(this, particularUri),
                        AccessStorageApi.getName(this, particularUri));
                greatUris.add(newUri);

                refreshList(newUri, true, false);
                arrayAdapter.selectPosition(newUri);
            }
            if (fileList.length > 0) {
                Uri particularUri = Uri.parse("file://" + fileList[0].getPath());
                final GreatUri newUri = new GreatUri(particularUri,
                        AccessStorageApi.getPath(this, particularUri),
                        AccessStorageApi.getName(this, particularUri));
                newFileToOpen(newUri, "");
            }

        } else {

            final Uri data = intent.getData();
            final GreatUri newUri = new GreatUri(data, AccessStorageApi.getPath(this, data),
                    AccessStorageApi.getName(this, data));

            // grantUriPermission(getPackageName(), data, Intent.FLAG_GRANT_READ_URI_PERMISSION);
            final int takeFlags = intent.getFlags()
                    & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            // Check for the freshest data.
            getContentResolver().takePersistableUriPermission(data, takeFlags);

            if (requestCode == READ_REQUEST_CODE || requestCode == CREATE_REQUEST_CODE) {

                newFileToOpen(newUri, "");
            }

            if (requestCode == SAVE_AS_REQUEST_CODE) {

                new SaveFileTask(this, newUri, pageSystem.getAllText(mEditor.getText().toString()),
                        currentEncoding, new SaveFileTask.SaveFileInterface() {
                            @Override
                            public void fileSaved(Boolean success) {
                                savedAFile(greatUri, false);
                                newFileToOpen(newUri, "");
                            }
                        }).execute();
            }
        }

    }
}

From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java

/**
* From:/*  ww w.  ja  va  2  s .  co m*/
* https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java
*
* MODIFIED FOR MAGE:
*
* - Removed LocalStorageProvider references
* - Added and modified to use isDocumentUri and getDocumentId methods with KITKAT target api annotation
* - Added ExternalStorageProvider SD card handler section in the getPath method
* - Added getFileIfExists method
*
 * Get a file path from a Uri. This will get the the path for Storage Access
 * Framework Documents, as well as the _data field for the MediaStore and
 * other file-based ContentProviders.<br>
 * <br>
 * Callers should check whether the path is local before assuming it
 * represents a local file.
 * 
 * @param context The context.
 * @param uri The Uri to query.
* @author paulburke
 */
public static String getPath(final Context context, final Uri uri) {

    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && isDocumentUri(context, uri)) {

        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }

            // Handle SD cards
            File file = getFileIfExists("/storage/extSdCard", split[1]);
            if (file != null) {
                return file.getAbsolutePath();
            }
            file = getFileIfExists("/storage/sdcard1", split[1]);
            if (file != null) {
                return file.getAbsolutePath();
            }
            file = getFileIfExists("/storage/usbcard1", split[1]);
            if (file != null) {
                return file.getAbsolutePath();
            }
            file = getFileIfExists("/storage/sdcard0", split[1]);
            if (file != null) {
                return file.getAbsolutePath();
            }

            // TODO handle non-primary volumes
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };

            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();

        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}