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:Main.java

public static boolean isSimilarUri(Uri one, Uri two) {
    return one.getHost().equals(two.getHost()) && one.getPath().equals(two.getPath());
}

From source file:Main.java

public static boolean isAssetUri(Uri paramUri) {
    if ((paramUri.getScheme().equals("file")) && (paramUri.getPath().startsWith(ANDROID_ASSET_PREFIX))) {
    }/*from   w  ww. j a  v  a 2s . c  o m*/
    for (boolean bool = true;; bool = false) {
        return bool;
    }
}

From source file:Main.java

private static Pair<String, String> getAddressVersion0(Uri uri) {
    final String path = uri.getPath();
    if ((path == null) || (path.length() <= 1)) {
        // Missing address.
        return null;
    }//w w w  .  j  ava2s  . com

    final String address = path.substring(1);
    if (!BluetoothAdapter.checkBluetoothAddress(address)) {
        // Invalid address.
        return null;
    }

    return new Pair<String, String>(address, null);
}

From source file:Main.java

public static Uri getUriFromPath(Context context, String path) {

    String fileName = "file:///sdcard/DCIM/Camera/2013_07_07_12345.jpg";
    Uri fileUri = Uri.parse(fileName);
    String filePath = fileUri.getPath();
    Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null,
            "_data = '" + filePath + "'", null, null);
    cursor.moveToNext();/*from  w ww.j  a v a  2s.c  om*/
    int id = cursor.getInt(cursor.getColumnIndex("_id"));
    Uri uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);

    return uri;
}

From source file:Main.java

public static void addPhotoToMediaStoreSynchronously(Context context, Uri uri) {
    MediaScannerConnection.scanFile(context, new String[] { uri.getPath() }, new String[] { "image/*" },
            new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {
                    Log.i("MediaStore", "Scanned " + path + ":");
                    Log.i("MediaStore", "-> uri=" + uri);
                }/*from   w ww.j a va  2  s  .c  o m*/
            });
}

From source file:Main.java

public static String prepareFilePathForVideoSaveWithDraftUri(Uri draftUri) {
    String draftPath = draftUri.getPath();
    String draftMediaDirPath = draftPath.substring(0, draftPath.length() - 5);
    File draftMediaDir = new File(draftMediaDirPath);
    if (!draftMediaDir.exists()) {
        draftMediaDir.mkdirs();/*  ww  w . j  a v a 2 s  . com*/
    }
    String[] files = draftMediaDir.list(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String filename) {
            return filename.endsWith("-0.mp4") || filename.endsWith("-a.mp4");
        }
    });
    List<String> filePaths = Arrays.asList(files);
    Collections.sort(filePaths, new Comparator<String>() {
        @Override
        public int compare(String lhs, String rhs) {
            return rhs.compareTo(lhs);
        }
    });
    if (filePaths.size() > 0) {
        for (String file : filePaths) {
            return new File(draftMediaDir, file.substring(0, file.length() - 6) + ".mp4").getAbsolutePath();
        }
    }
    return new File(draftMediaDir, generateRandomFilename("mp4")).getAbsolutePath();
}

From source file:Main.java

private static String fileUriTitle(Context context, String contentUri) {
    String result = null;// w  w  w.  jav  a2 s.  c  o m
    String[] p = { MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.TITLE };
    Uri uri = Uri.parse(contentUri);
    String path = uri.getPath();
    String last = Uri.parse(path).getLastPathSegment();
    Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, p, // which columns
            MediaStore.MediaColumns.DISPLAY_NAME + "='" + last + "'", // which rows
            null, // selection args (none)
            null); // order-by clause (ascending by name)
    if (cursor != null) {
        int tcol = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.TITLE);
        if (cursor.moveToFirst()) {
            result = cursor.getString(tcol);
        }
    }
    return (result);
}

From source file:Main.java

private static long fileUriFileSize(Context context, String contentUri) {
    long result = 0;
    String[] p = { MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.SIZE };
    Uri uri = Uri.parse(contentUri);
    String path = uri.getPath();
    String last = Uri.parse(path).getLastPathSegment();
    Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, p, // which columns
            MediaStore.MediaColumns.DISPLAY_NAME + "='" + last + "'", // which rows
            null, // selection args (none)
            null); // order-by clause (ascending by name)
    if (cursor != null) {
        int scol = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE);
        if (cursor.moveToFirst()) {
            result = cursor.getLong(scol);
        }//from   w  w  w  . j ava  2  s  .c  om
    }
    return (result);
}

From source file:Main.java

public static boolean deleteTempPic(Uri paramUri) {
    if (!isTempPic(paramUri))
        return false;
    return new File(paramUri.getPath()).delete();
}

From source file:Main.java

public static Bitmap fixBitmapOrientation(Uri uri, Bitmap bmp) throws IOException {
    ExifInterface ei = new ExifInterface(uri.getPath());
    int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

    switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        return rotateBitmap(bmp, 90);
    case ExifInterface.ORIENTATION_ROTATE_180:
        return rotateBitmap(bmp, 180);
    case ExifInterface.ORIENTATION_ROTATE_270:
        return rotateBitmap(bmp, 270);
    }/*from w w w .ja  v a 2 s. c  o m*/

    return bmp;
}