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.liwn.zzl.markbit.DrawOptionsMenuActivity.java

private Uri rotateNormal(Uri uri) throws IOException {
    ExifInterface exif = new ExifInterface(uri.getPath());
    int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    int rotationInDegrees = exifToDegrees(rotation);
    Matrix matrix = new Matrix();
    if (rotation != 0) {
        matrix.preRotate(rotationInDegrees);
    }//from  w ww.jav a  2 s . c  o  m
    Bitmap srcBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
    Bitmap adjustedBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, MarkBitApplication.BIT_LCD_WIDTH,
            MarkBitApplication.BIT_LCD_HEIGHT, matrix, true);
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    adjustedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(this.getContentResolver(), adjustedBitmap, "Title", null);
    return Uri.parse(path);
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.PhotoUploadWidget.java

private void pickSizePhoto(Uri uri) {
    File file = new File(uri.getPath());
    long size = file.length();
    long large = 600000;
    long medium = 200000;
    long small = 75000;
    final String[] items;
    final long[] sizes;

    if (size > 600000) {
        sizes = new long[] { size, large, medium, small };
        items = new String[] { mActivity.getString(R.string.size_actual) + " (" + size / 1000 + " KB)",
                mActivity.getString(R.string.size_large) + " (" + large / 1000 + " KB)",
                mActivity.getString(R.string.size_medium) + " (" + medium / 1000 + " KB)",
                mActivity.getString(R.string.size_small) + " (" + small / 1000 + " KB)" };
    } else if (size > 200000) {
        sizes = new long[] { size, medium, small };
        items = new String[] { mActivity.getString(R.string.size_actual) + " (" + size / 1000 + " KB)",
                mActivity.getString(R.string.size_medium) + " (" + medium / 1000 + " KB)",
                mActivity.getString(R.string.size_small) + " (" + small / 1000 + " KB)" };
    } else if (size > 75000) {
        sizes = new long[] { size, small };
        items = new String[] { mActivity.getString(R.string.size_actual) + " (" + size / 1000 + " KB)",
                mActivity.getString(R.string.size_small) + " (" + small / 1000 + " KB)" };
    } else {/*from  w  w  w.j a v a 2  s.  c o  m*/
        sizes = new long[] { size };
        items = new String[] { mActivity.getString(R.string.size_actual) + " (" + size / 1000 + " KB)" };
        // don't ask
    }
    if (size > 75000) {
        String title = mActivity.getString(R.string.select_size);
        SafeDialogClick itemsOnClickListener = new SafeDialogClick() {
            @Override
            public void safeOnClick(DialogInterface dialog, int id) {
                IOUtils.compressPicture(mUriSavedImage, sizes[id]);
            }
        };
        UIUtils.showDialog(mActivity, title, null, items, itemsOnClickListener);
    }
}

From source file:com.imagine.BaseActivity.java

String intentDataPath() {
    //Log.i(logTag, "intent action: " + getIntent().getAction());
    String path = null;/*from w  ww  .  ja v a  2  s .co m*/
    Uri uri = getIntent().getData();
    if (uri != null) {
        path = uri.getPath();
        //Log.i(logTag, "path: " + path);
        getIntent().setData(null); // data is one-time use
    }
    return path;
}

From source file:com.dropbox.android.sample.DBRoulette.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CHOOSE_FILE) {
        // return from file upload
        if (resultCode == Activity.RESULT_OK) {
            Uri uri = null;
            if (data != null) {
                uri = data.getData();/*from  ww w .  j a  v  a2 s.  c  o m*/
            }

            if (uri != null) {
                String path = uri.getPath();
                System.out.println(uri.getLastPathSegment());
                if (path.startsWith("/file"))
                    path = path.replace("/file", "");
                operations.UploadFile(MyDropbox_DIR, new File(path), mList);
            }
        } else {
            Log.w(TAG, "Unknown Activity Result from mediaImport: " + resultCode);
        }
    }
}

From source file:com.cw.litenote.note_add.Note_addCameraVideo.java

protected void onActivityResult(int requestCode, int resultCode, Intent videoReturnedIntent) {
    System.out.println("Note_addCameraVideo / onActivityResult");
    if (requestCode == TAKE_VIDEO_ACT) {
        if (resultCode == Activity.RESULT_OK) {
            // disable Rotate to avoid leak window
            //            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

            // Note: 
            // for Google Camera App, imageReturnedIntent is null
            // default path of Google camera is /sdcard/DCIM/Camera 

            // check returned intent
            Uri intentVideoUri = null;//from   w  w  w . j  a  va2  s.c  om
            if (videoReturnedIntent == null) {
                System.out.println("returned intent is null");
            } else {
                intentVideoUri = videoReturnedIntent.getData();

                if (intentVideoUri == null)
                    System.out.println("-- videoUri = " + null);
                else
                    System.out.println("-- videoUri = " + intentVideoUri.toString());
            }

            // set for Rotate any times
            if (noteId != null) {
                cameraVideoUri = dB_page.getNotePictureUri_byId(noteId);
            }

            // Add for Sony, the file size is 0 for given file name by putExtra 
            if (videoReturnedIntent != null) {
                Uri uri = Uri.parse(cameraVideoUri);
                File file = new File(uri.getPath());

                // update file name by returned intent
                if (file.length() == 0) {
                    System.out.println("--- file size = 0");
                    String path = Util.getLocalRealPathByUri(Note_addCameraVideo.this, intentVideoUri);
                    videoUriInDB = "file://" + path;
                    enSaveDb = true;
                    noteId = savePictureStateInDB(noteId, videoUriInDB);
                    enSaveDb = false;
                }
            }

            if (getIntent().getExtras().getString("extra_ADD_NEW_TO_TOP", "false").equalsIgnoreCase("true")
                    && (dB_page.getNotesCount(true) > 0))
                Page_recycler.swap(Page_recycler.mDb_page);

            Toast.makeText(this, R.string.toast_saved, Toast.LENGTH_SHORT).show();

            // check and delete duplicated image file in 100ANDRO (Sony) / 100MEDIA (hTC)
            int lastContentId = getLastCapturedVideoId(this);
            handleDuplicatedVideo(this, lastContentId);

            noteId = null; // set null for Insert
            takeVideoWithName();
        } else if (resultCode == RESULT_CANCELED) {
            // hide action bar
            if (getActionBar() != null)
                getActionBar().hide();

            // set background to transparent
            getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

            Toast.makeText(this, R.string.note_cancel_add_new, Toast.LENGTH_LONG).show();

            // delete the temporary note in DB
            if (noteId != null)
                dB_page.deleteNote(noteId, true);

            // When auto time out of taking picture App happens, 
            // Note_addCameraVideo activity will start from onCreate,
            // at this case, mImageUri is null
            if (videoUri != null) {
                File tempFile = new File(videoUri.getPath());
                if (tempFile.isFile()) {
                    // delete 0 bit temporary file
                    tempFile.delete();
                    System.out.println("temp 0 bit file is deleted");
                }
            }
            finish();
            return; // must add this
        }

    }
}

From source file:com.cw.litenote.note_add.Note_addCameraVideo.java

public void handleDuplicatedVideo(Context context, int lastContentId) {
    /*/*from w  w  w .  j a v a2 s .c  o m*/
     * Checking for duplicate images
     * This is necessary because some camera implementation not only save where you want them to save but also in their default location.
     */
    if (lastContentId == 0)
        return;

    final String[] projection = { MediaStore.Video.VideoColumns.DATA, MediaStore.Video.VideoColumns.DATE_TAKEN,
            MediaStore.Video.VideoColumns.SIZE, MediaStore.Video.VideoColumns._ID };
    final String videoWhere = MediaStore.Video.Media._ID + "=?";
    final String[] videoArguments = { Integer.toString(lastContentId) };
    final String videoOrderBy = MediaStore.Video.Media._ID + " DESC";

    Cursor videoCursor = context.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            projection, videoWhere, videoArguments, videoOrderBy);

    // last file: file1
    // new file: file2
    String path1 = null;
    File file1 = null;
    long dateTaken = 0;
    if (videoCursor.getCount() > 0) {
        videoCursor.moveToFirst(); // newest one
        path1 = videoCursor.getString(videoCursor.getColumnIndex(MediaStore.Video.Media.DATA));
        dateTaken = videoCursor.getLong(videoCursor.getColumnIndex(MediaStore.Video.Media.DATE_TAKEN));
        System.out.println("date taken = " + Util.getTimeString(dateTaken));
        System.out.println("last Id point to file path: " + path1);
        file1 = new File(path1);
    } else
        System.out.println("videoCursor.getCount() = " + videoCursor.getCount());

    videoCursor.close();

    Uri uri = Uri.parse(videoUriInDB);
    File file2 = new File(uri.getPath());

    System.out.println("- file1 size = " + file1.length());
    System.out.println("- file1 path = " + file1.getPath());
    System.out.println("- file2 size = " + file2.length());
    System.out.println("- file2 path = " + file2.getPath());

    boolean isSameSize = false;
    if (file1.length() == file2.length()) {
        System.out.println("-- file lenghts are the same");
        isSameSize = true;
    } else
        System.out.println("-- files are different");

    boolean isSameFilePath = false;
    if (file1.getPath().equalsIgnoreCase(file2.getPath())) {
        System.out.println("-- file paths are the same");
        isSameFilePath = true;
    } else
        System.out.println("-- file paths are different");

    // Check time for avoiding Delete existing file, since lastContentId could points to 
    // wrong file by experiment
    Date now = new Date();
    System.out.println("current time = " + Util.getTimeString(now.getTime()));
    long elapsedTime = Math.abs(dateTaken - now.getTime());

    // check if there is a duplicated file
    if (isSameSize && !isSameFilePath && (file1 != null) && (elapsedTime < 10000)) // tolerance 10 seconds
    {
        // delete file
        // for ext_sd file, it can not be deleted after Kitkat, so this will be false
        boolean bDeleteFile1 = file1.delete();

        // check if default image file is deleted
        if (bDeleteFile1) {
            System.out.println("deleted file path1 = " + path1);
            String repPath = path1;

            // delete 
            int deletedRows = context.getContentResolver().delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                    MediaStore.Video.VideoColumns.DATA + "='" + repPath + "'", null);

            System.out.println("deleted thumbnail deletedRows = " + deletedRows);
        } else {
            boolean bDeleteFile2 = file2.delete();

            // check if self-naming file is deleted
            if (bDeleteFile2) {
                System.out.println("deleted file path1 = " + file2.getPath());
                String repPath = file2.getPath();

                // update new Uri to DB
                videoUriInDB = "file://" + Uri.parse(file1.getPath()).toString();

                // set for Rotate any times
                if (noteId != null) {
                    cameraVideoUri = dB_page.getNotePictureUri_byId(noteId);
                }

                // delete
                int deletedRows = context.getContentResolver().delete(
                        MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                        MediaStore.Video.VideoColumns.DATA + "='" + repPath + "'", null);

                System.out.println("deleted thumbnail deletedRows = " + deletedRows);
            }
        }
    }
}

From source file:com.android.nfc.beam.BeamTransferManager.java

void cancel() {
    if (!isRunning())
        return;/*from  w ww .jav a 2  s  .  c o  m*/

    // Delete all files received so far
    for (Uri uri : mUris) {
        File file = new File(uri.getPath());
        if (file.exists())
            file.delete();
    }

    if (mBluetoothTransferId != -1) {
        // we know the ID, we can cancel immediately
        sendBluetoothCancelIntentAndUpdateState();
    } else {
        updateStateAndNotification(STATE_CANCELLING);
    }

}

From source file:org.ueu.uninet.it.IragarkiaBidali.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case PICK_IMAGE:
        if (resultCode == Activity.RESULT_OK) {
            Uri selectedImageUri = data.getData();

            try {
                // OI Fitxategi kudeatzailea
                String filemanagerstring = selectedImageUri.getPath();

                // MEDIA galeria
                String selectedImagePath = getPath(selectedImageUri);

                if (selectedImagePath != null) {
                    filePath = selectedImagePath;
                } else if (filemanagerstring != null) {
                    filePath = filemanagerstring;
                } else {
                    Toast.makeText(getApplicationContext(), "Kokapen ezezaguna", Toast.LENGTH_LONG).show();
                }//from w  w w .j av a  2  s  .  c  o m

                if (filePath != null) {
                    Thread haria = new Thread() {
                        @Override
                        public void run() {
                            decodeFile(filePath);
                        }
                    };
                    haria.run();

                } else {
                    bitmap = null;
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), "Barne-errore bat egon da.", Toast.LENGTH_LONG).show();
            }
        }
        break;
    default:
    }
}

From source file:com.samuelcastro.cordova.InstagramSharePlugin.java

public String getRealVideoPathFromURI(Uri contentUri) {
    try {/* w  ww.j a va2  s .c o m*/
        String[] proj = { MediaStore.Video.Media.DATA };
        Cursor cursor = cordova.getActivity().getContentResolver().query(contentUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    } catch (Exception e) {
        return contentUri.getPath();
    }
}

From source file:com.alibaba.weex.WXPageActivity.java

private String assembleFilePath(Uri uri) {
    if (uri != null && uri.getPath() != null) {
        return uri.getPath().replaceFirst("/", "");
    }//from ww  w .j a v  a2  s .co  m
    return "";
}