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:com.ludoscity.findmybikes.activities.NearbyActivity.java

@Override
public void onStationMapFragmentInteraction(final Uri uri) {
    //Will be warned of station details click, will make info fragment to replace list fragment

    //Map ready//w w w  .j  a v a 2s  . com
    if (uri.getPath().equalsIgnoreCase("/" + StationMapFragment.MAP_READY_PATH)) {
        long wishedUpdateTime = DBHelper.getLastUpdateTimestamp(getApplicationContext())
                + NearbyActivity.this.getApplicationContext().getResources()
                        .getInteger(R.integer.update_auto_interval_minute) * 1000 * 60; //comes from Prefs

        if (mDownloadWebTask == null && !( //if no download task been launched but conditions are met that one will be launched imminently, don't refresh map
        DBHelper.getAutoUpdate(this) && System.currentTimeMillis() >= wishedUpdateTime
                && Utils.Connectivity.isConnected(this)))
            refreshMap();
    }
    //Marker click - ignored if onboarding is in progress
    else if (uri.getPath().equalsIgnoreCase("/" + StationMapFragment.MARKER_CLICK_PATH)
            && mOnboardingShowcaseView == null) {

        if (!isLookingForBike() || mStationMapFragment.getMarkerBVisibleLatLng() != null) {

            if (isLookingForBike()) {

                if (getListPagerAdapter().highlightStationForPage(
                        uri.getQueryParameter(StationMapFragment.MARKER_CLICK_TITLE_PARAM),
                        StationListPagerAdapter.BIKE_STATIONS)) {

                    getListPagerAdapter().smoothScrollHighlightedInViewForPage(
                            StationListPagerAdapter.BIKE_STATIONS, isAppBarExpanded());

                    mStationMapFragment.setPinOnStation(true,
                            uri.getQueryParameter(StationMapFragment.MARKER_CLICK_TITLE_PARAM));
                    getListPagerAdapter().setupBTabStationARecap(getListPagerAdapter()
                            .getHighlightedStationForPage(StationListPagerAdapter.BIKE_STATIONS),
                            mDataOutdated);

                    if (mStationMapFragment.getMarkerBVisibleLatLng() != null) {
                        LatLng newALatLng = mStationMapFragment.getMarkerALatLng();
                        getListPagerAdapter().notifyStationAUpdate(newALatLng, mCurrentUserLatLng);
                        hideSetupShowTripDetailsWidget();

                        if ((getListPagerAdapter().getClosestBikeLatLng().latitude != newALatLng.latitude)
                                && (getListPagerAdapter()
                                        .getClosestBikeLatLng().longitude != newALatLng.longitude)) {

                            mStationMapFragment.setMapPaddingRight(
                                    (int) getResources().getDimension(R.dimen.map_fab_padding));
                            mAutoSelectBikeFab.show();
                            animateCameraToShowUserAndStation(getListPagerAdapter()
                                    .getHighlightedStationForPage(StationListPagerAdapter.BIKE_STATIONS));

                        }
                    }
                }
            } else {

                if (mAppBarLayout != null)
                    mAppBarLayout.setExpanded(false, true);

                //B Tab, looking for dock
                final String clickedStationId = uri
                        .getQueryParameter(StationMapFragment.MARKER_CLICK_TITLE_PARAM);
                setupBTabSelection(clickedStationId, false);

                boolean showFavoriteAddFab = false;

                if (!mStationMapFragment.isPickedFavoriteMarkerVisible()) {
                    if (mStationMapFragment.isPickedPlaceMarkerVisible())
                        showFavoriteAddFab = true; //Don't setup the fab as it's been done in OnActivityResult
                    else if (setupAddFavoriteFab(new FavoriteItemStation(clickedStationId,
                            getStation(clickedStationId).getName(), true)))
                        showFavoriteAddFab = true;
                }

                if (showFavoriteAddFab)
                    mAddFavoriteFAB.show();
                else
                    mAddFavoriteFAB.hide();
            }
        } else {

            Utils.Snackbar.makeStyled(mCoordinatorLayout, R.string.onboarding_hint_main_choice,
                    Snackbar.LENGTH_SHORT, ContextCompat.getColor(this, R.color.theme_primary_dark)).show();

            mStationListViewPager.setCurrentItem(StationListPagerAdapter.DOCK_STATIONS, true);
        }
    }
}

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

public static String getFilePathFromUri(Context c, Uri uri) {
    String filePath = null;/*from   w  w w.j  a va  2 s.  c o m*/
    if ("content".equals(uri.getScheme())) {
        String[] filePathColumn = { MediaStore.MediaColumns.DATA };
        ContentResolver contentResolver = c.getContentResolver();

        Cursor cursor = contentResolver.query(uri, filePathColumn, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            filePath = cursor.getString(columnIndex);
            cursor.close();
        }
    } else if ("file".equals(uri.getScheme())) {
        filePath = new File(uri.getPath()).getAbsolutePath();
    }
    return filePath;
}

From source file:com.cordova.photo.CameraLauncher.java

/**
 * Applies all needed transformation to the image received from the camera.
 *
 * @param destType          In which form should we return the image
 * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 *///w w w.jav a 2 s. c  o m
private void processResultFromCamera(int destType, Intent intent) throws IOException {
    int rotate = 0;

    // Create an ExifHelper to save the exif data that is lost during compression
    ExifHelper exif = new ExifHelper();
    try {
        if (this.encodingType == JPEG) {
            exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg");
            exif.readExifData();
            rotate = exif.getOrientation();
        } else if (this.encodingType == PNG) {
            exif.createInFile(getTempDirectoryPath() + "/.Pic.png");
            exif.readExifData();
            rotate = exif.getOrientation();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    Bitmap bitmap = null;
    Uri uri = null;

    // If sending base64 image back
    if (destType == DATA_URL) {
        if (imageUri != null)
            bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
        if (bitmap == null) {
            // Try to get the bitmap from intent.
            if (intent != null && intent.getExtras() != null) {
                bitmap = (Bitmap) intent.getExtras().get("data");
            }
        }

        // Double-check the bitmap.
        if (bitmap == null) {
            Log.d(LOG_TAG, "I either have a null image path or bitmap");
            this.failPicture("Unable to create bitmap!");
            return;
        }

        if (rotate != 0 && this.correctOrientation) {
            bitmap = getRotatedBitmap(rotate, bitmap, exif);
        }

        this.processPicture(bitmap);
        checkForDuplicateImage(DATA_URL);
    }

    // If sending filename back
    else if (destType == FILE_URI || destType == NATIVE_URI) {
        if (this.saveToPhotoAlbum) {
            Uri inputUri = getUriFromMediaStore();
            try {
                //Just because we have a media URI doesn't mean we have a real file, we need to make it
                uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.activity)));
            } catch (NullPointerException e) {
                uri = null;
            }
        } else {
            uri = Uri.fromFile(new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg"));
        }

        if (uri == null) {
            this.failPicture("Error capturing image - no media storage found.");
            return;
        }

        // If all this is true we shouldn't compress the image.
        if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100
                && !this.correctOrientation) {
            writeUncompressedImage(uri);

            this.callbackContext.success(uri.toString());
        } else {
            bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));

            if (rotate != 0 && this.correctOrientation) {
                bitmap = getRotatedBitmap(rotate, bitmap, exif);
            }

            // Add compressed version of captured image to returned media store Uri
            OutputStream os = this.activity.getContentResolver().openOutputStream(uri);
            bitmap.compress(CompressFormat.JPEG, this.mQuality, os);
            os.close();

            // Restore exif data to file
            if (this.encodingType == JPEG) {
                String exifPath;
                if (this.saveToPhotoAlbum) {
                    exifPath = FileHelper.getRealPath(uri, this.activity);
                } else {
                    exifPath = uri.getPath();
                }
                exif.createOutFile(exifPath);
                exif.writeExifData();
            }
            if (this.allowEdit) {
                performCrop(uri);
            } else {
                // Send Uri back to JavaScript for viewing image
                this.callbackContext.success(uri.toString());
            }
        }
    } else {
        throw new IllegalStateException();
    }

    this.cleanup(FILE_URI, this.imageUri, uri, bitmap);
    bitmap = null;
}

From source file:com.android.mail.compose.ComposeActivity.java

/**
 * Helper function to handle a list of uris to attach.
 * @return the total size of all successfully attached files.
 *///from   w  w  w  .  j a  v  a2 s  .c  o  m
private long handleAttachmentUrisFromIntent(List<Uri> uris) {
    ArrayList<Attachment> attachments = Lists.newArrayList();
    for (Uri uri : uris) {
        try {
            if (uri != null) {
                if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
                    // We must not allow files from /data, even from our process.
                    final File f = new File(uri.getPath());
                    final String filePath = f.getCanonicalPath();
                    if (filePath.startsWith(DATA_DIRECTORY_ROOT)) {
                        showErrorToast(getString(R.string.attachment_permission_denied));
                        Analytics.getInstance().sendEvent(ANALYTICS_CATEGORY_ERRORS, "send_intent_attachment",
                                "data_dir", 0);
                        continue;
                    }
                } else if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
                    // disallow attachments from our own EmailProvider (b/27308057)
                    if (getEmailProviderAuthority().equals(uri.getAuthority())) {
                        showErrorToast(getString(R.string.attachment_permission_denied));
                        Analytics.getInstance().sendEvent(ANALYTICS_CATEGORY_ERRORS, "send_intent_attachment",
                                "email_provider", 0);
                        continue;
                    }
                }

                if (!handleSpecialAttachmentUri(uri)) {
                    final Attachment a = mAttachmentsView.generateLocalAttachment(uri);
                    attachments.add(a);

                    Analytics.getInstance().sendEvent("send_intent_attachment",
                            Utils.normalizeMimeType(a.getContentType()), null, a.size);
                }
            }
        } catch (AttachmentFailureException e) {
            LogUtils.e(LOG_TAG, e, "Error adding attachment");
            showAttachmentTooBigToast(e.getErrorRes());
        } catch (IOException | SecurityException e) {
            LogUtils.e(LOG_TAG, e, "Error adding attachment");
            showErrorToast(getString(R.string.attachment_permission_denied));
        }
    }
    return addAttachments(attachments);
}

From source file:com.tuxpan.foregroundcameragalleryplugin.ForegroundCameraLauncher.java

/**
 * Called when the camera view exits./* www.  j  a  va 2s .  c om*/
 *
 * @param requestCode       The request code originally supplied to startActivityForResult(),
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 */
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    // Get src and dest types from request code
    int srcType = (requestCode / 16) - 1;
    int destType = (requestCode % 16) - 1;
    int rotate = 0;

    // If CAMERA
    if (srcType == CAMERA) {
        // If image available
        if (resultCode == Activity.RESULT_OK) {
            try {
                // Create an ExifHelper to save the exif data that is lost during compression
                ExifHelper exif = new ExifHelper();
                try {
                    if (this.encodingType == JPEG) {
                        exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg");
                        exif.readExifData();
                        rotate = exif.getOrientation();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

                Bitmap bitmap = null;
                Uri uri = null;

                // If sending base64 image back
                if (destType == DATA_URL) {
                    bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
                    if (bitmap == null) {
                        // Try to get the bitmap from intent.
                        bitmap = (Bitmap) intent.getExtras().get("data");
                    }

                    // Double-check the bitmap.
                    if (bitmap == null) {
                        Log.d(LOG_TAG, "I either have a null image path or bitmap");
                        this.failPicture("Unable to create bitmap!");
                        return;
                    }

                    if (rotate != 0 && this.correctOrientation) {
                        bitmap = getRotatedBitmap(rotate, bitmap, exif);
                    }

                    this.processPicture(bitmap);
                    checkForDuplicateImage(DATA_URL);
                }

                // If sending filename back
                else if (destType == FILE_URI || destType == NATIVE_URI) {
                    if (this.saveToPhotoAlbum) {
                        Uri inputUri = getUriFromMediaStore();
                        //Just because we have a media URI doesn't mean we have a real file, we need to make it
                        uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova)));
                    } else {
                        uri = Uri.fromFile(
                                new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg"));
                    }

                    if (uri == null) {
                        this.failPicture("Error capturing image - no media storage found.");
                    }

                    // If all this is true we shouldn't compress the image.
                    if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100
                            && !this.correctOrientation) {
                        writeUncompressedImage(uri);

                        this.callbackContext.success(uri.toString());
                    } else {
                        bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));

                        if (rotate != 0 && this.correctOrientation) {
                            bitmap = getRotatedBitmap(rotate, bitmap, exif);
                        }

                        // Add compressed version of captured image to returned media store Uri
                        OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
                        bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
                        os.close();

                        // Restore exif data to file
                        if (this.encodingType == JPEG) {
                            String exifPath;
                            if (this.saveToPhotoAlbum) {
                                exifPath = FileHelper.getRealPath(uri, this.cordova);
                            } else {
                                exifPath = uri.getPath();
                            }
                            exif.createOutFile(exifPath);
                            exif.writeExifData();
                        }

                    }
                    // Send Uri back to JavaScript for viewing image
                    this.callbackContext.success(uri.toString());
                }

                this.cleanup(FILE_URI, this.imageUri, uri, bitmap);
                bitmap = null;

            } catch (IOException e) {
                e.printStackTrace();
                this.failPicture("Error capturing image.");
            }
        }

        // If cancelled
        else if (resultCode == Activity.RESULT_CANCELED) {
            this.failPicture("Camera cancelled.");
        }

        // If something else
        else {
            this.failPicture("Did not complete!");
        }
    }

    // If retrieving photo from library
    else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
        if (resultCode == Activity.RESULT_OK) {
            Uri uri = intent.getData();

            // If you ask for video or all media type you will automatically get back a file URI
            // and there will be no attempt to resize any returned data
            if (this.mediaType != PICTURE) {
                this.callbackContext.success(uri.toString());
            } else {
                // This is a special case to just return the path as no scaling,
                // rotating, nor compressing needs to be done
                if (this.targetHeight == -1 && this.targetWidth == -1
                        && (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) {
                    this.callbackContext.success(uri.toString());
                } else {
                    String uriString = uri.toString();
                    // Get the path to the image. Makes loading so much easier.
                    String mimeType = FileHelper.getMimeType(uriString, this.cordova);
                    // If we don't have a valid image so quit.
                    if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) {
                        Log.d(LOG_TAG, "I either have a null image path or bitmap");
                        this.failPicture("Unable to retrieve path to picture!");
                        return;
                    }
                    Bitmap bitmap = null;
                    try {
                        bitmap = getScaledBitmap(uriString);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    if (bitmap == null) {
                        Log.d(LOG_TAG, "I either have a null image path or bitmap");
                        this.failPicture("Unable to create bitmap!");
                        return;
                    }

                    if (this.correctOrientation) {
                        rotate = getImageOrientation(uri);
                        if (rotate != 0) {
                            //                                Matrix matrix = new Matrix();
                            //                                matrix.setRotate(rotate);
                            //                                bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
                            RotateTask r = new RotateTask(bitmap, srcType, destType, rotate, intent);
                            r.execute();
                            return;
                        }
                    }
                    returnImageToProcess(bitmap, srcType, destType, intent, rotate);
                }
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            this.failPicture("Selection cancelled.");
        } else {
            this.failPicture("Selection did not complete!");
        }
    }
}

From source file:io.strider.camera.CameraLauncher.java

/**
 * Called when the camera view exits.//from   w w w.j  a  v a2s . co m
 *
 * @param requestCode       The request code originally supplied to startActivityForResult(),
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 */
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    // Get src and dest types from request code
    int srcType = (requestCode / 16) - 1;
    int destType = (requestCode % 16) - 1;
    int rotate = 0;

    // If CAMERA
    if (srcType == CAMERA) {
        // If image available
        if (resultCode == Activity.RESULT_OK) {
            try {
                // Create an ExifHelper to save the exif data that is lost during compression
                ExifHelper exif = new ExifHelper();
                try {
                    if (this.encodingType == JPEG) {
                        exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg");
                        exif.readExifData();
                        rotate = exif.getOrientation();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

                Bitmap bitmap = null;
                Uri uri = null;

                // If sending base64 image back
                if (destType == DATA_URL) {
                    bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
                    if (bitmap == null) {
                        // Try to get the bitmap from intent.
                        bitmap = (Bitmap) intent.getExtras().get("data");
                    }

                    // Double-check the bitmap.
                    if (bitmap == null) {
                        Log.d(LOG_TAG, "I either have a null image path or bitmap");
                        this.failPicture("Unable to create bitmap!");
                        return;
                    }

                    if (rotate != 0 && this.correctOrientation) {
                        bitmap = getRotatedBitmap(rotate, bitmap, exif);
                    }

                    this.processPicture(bitmap);
                    checkForDuplicateImage(DATA_URL);
                }

                // If sending filename back
                else if (destType == FILE_URI || destType == NATIVE_URI) {
                    if (this.saveToPhotoAlbum) {
                        Uri inputUri = getUriFromMediaStore();
                        //Just because we have a media URI doesn't mean we have a real file, we need to make it
                        uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova)));
                    } else {
                        uri = Uri.fromFile(
                                new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg"));
                    }

                    if (uri == null) {
                        this.failPicture("Error capturing image - no media storage found.");
                    }

                    // If all this is true we shouldn't compress the image.
                    if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100
                            && !this.correctOrientation) {
                        writeUncompressedImage(uri);

                        this.callbackContext.success(uri.toString());
                    } else {
                        bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));

                        if (rotate != 0 && this.correctOrientation) {
                            bitmap = getRotatedBitmap(rotate, bitmap, exif);
                        }

                        // Add compressed version of captured image to returned media store Uri
                        OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
                        bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
                        os.close();

                        // Restore exif data to file
                        if (this.encodingType == JPEG) {
                            String exifPath;
                            if (this.saveToPhotoAlbum) {
                                exifPath = FileHelper.getRealPath(uri, this.cordova);
                            } else {
                                exifPath = uri.getPath();
                            }
                            exif.createOutFile(exifPath);
                            exif.writeExifData();
                        }

                    }
                    // Send Uri back to JavaScript for viewing image
                    this.callbackContext.success(uri.toString());
                }

                this.cleanup(FILE_URI, this.imageUri, uri, bitmap);
                bitmap = null;

            } catch (IOException e) {
                e.printStackTrace();
                this.failPicture("Error capturing image.");
            }
        }

        // If cancelled
        else if (resultCode == Activity.RESULT_CANCELED) {
            this.failPicture("Camera cancelled.");
        }

        // If something else
        else {
            this.failPicture("Did not complete!");
        }
    }

    //      // If retrieving photo from library
    //      else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
    //         if (resultCode == Activity.RESULT_OK) {
    //            Uri uri = intent.getData();
    //
    //            // If you ask for video or all media type you will automatically get back a file URI
    //            // and there will be no attempt to resize any returned data
    //            if (this.mediaType != PICTURE) {
    //               this.callbackContext.success(uri.toString());
    //            }
    //            else {
    //               // This is a special case to just return the path as no scaling,
    //               // rotating, nor compressing needs to be done
    //               if (this.targetHeight == -1 && this.targetWidth == -1 &&
    //                     (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) {
    //                  this.callbackContext.success(uri.toString());
    //               } else {
    //                  String uriString = uri.toString();
    //                  // Get the path to the image. Makes loading so much easier.
    //                  String mimeType = FileHelper.getMimeType(uriString, this.cordova);
    //                  // If we don't have a valid image so quit.
    //                  if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) {
    //                     Log.d(LOG_TAG, "I either have a null image path or bitmap");
    //                     this.failPicture("Unable to retrieve path to picture!");
    //                     return;
    //                  }
    //                  Bitmap bitmap = null;
    //                  try {
    //                     bitmap = getScaledBitmap(uriString);
    //                  } catch (IOException e) {
    //                     e.printStackTrace();
    //                  }
    //                  if (bitmap == null) {
    //                     Log.d(LOG_TAG, "I either have a null image path or bitmap");
    //                     this.failPicture("Unable to create bitmap!");
    //                     return;
    //                  }
    //
    //                  if (this.correctOrientation) {
    //                     rotate = getImageOrientation(uri);
    //                     if (rotate != 0) {
    //                        Matrix matrix = new Matrix();
    //                        matrix.setRotate(rotate);
    //                        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    //                     }
    //                  }
    //
    //                  // If sending base64 image back
    //                  if (destType == DATA_URL) {
    //                     this.processPicture(bitmap);
    //                  }
    //
    //                  // If sending filename back
    //                  else if (destType == FILE_URI || destType == NATIVE_URI) {
    //                     // Do we need to scale the returned file
    //                     if (this.targetHeight > 0 && this.targetWidth > 0) {
    //                        try {
    //                           // Create an ExifHelper to save the exif data that is lost during compression
    //                           String resizePath = getTempDirectoryPath() + "/resize.jpg";
    //                           // Some content: URIs do not map to file paths (e.g. picasa).
    //                           String realPath = FileHelper.getRealPath(uri, this.cordova);
    //                           ExifHelper exif = new ExifHelper();
    //                           if (realPath != null && this.encodingType == JPEG) {
    //                              try {
    //                                 exif.createInFile(realPath);
    //                                 exif.readExifData();
    //                                 rotate = exif.getOrientation();
    //                              } catch (IOException e) {
    //                                 e.printStackTrace();
    //                              }
    //                           }
    //
    //                           OutputStream os = new FileOutputStream(resizePath);
    //                           bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
    //                           os.close();
    //
    //                           // Restore exif data to file
    //                           if (realPath != null && this.encodingType == JPEG) {
    //                              exif.createOutFile(resizePath);
    //                              exif.writeExifData();
    //                           }
    //
    //                           // The resized image is cached by the app in order to get around this and not have to delete you
    //                           // application cache I'm adding the current system time to the end of the file url.
    //                           this.callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis());
    //                        } catch (Exception e) {
    //                           e.printStackTrace();
    //                           this.failPicture("Error retrieving image.");
    //                        }
    //                     }
    //                     else {
    //                        this.callbackContext.success(uri.toString());
    //                     }
    //                  }
    //                  if (bitmap != null) {
    //                     bitmap.recycle();
    //                     bitmap = null;
    //                  }
    //                  System.gc();
    //               }
    //            }
    //         }
    //         else if (resultCode == Activity.RESULT_CANCELED) {
    //            this.failPicture("Selection cancelled.");
    //         }
    //         else {
    //            this.failPicture("Selection did not complete!");
    //         }
    //      }
}

From source file:com.if3games.chessonline.DroidFish.java

public static String getFilePathFromUri(Uri uri) {
    if (uri == null)
        return null;
    return uri.getPath();
}