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.jtechme.apphub.FDroid.java

private void handleSearchOrAppViewIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        performSearch(query);//from   w  w  w .jav  a2  s.c om
        return;
    }

    final Uri data = intent.getData();
    if (data == null) {
        return;
    }

    final String scheme = data.getScheme();
    final String path = data.getPath();
    String packageName = null;
    String query = null;
    if (data.isHierarchical()) {
        final String host = data.getHost();
        if (host == null) {
            return;
        }
        switch (host) {
        case "f-droid.org":
            if (path.startsWith("/repository/browse")) {
                // http://f-droid.org/repository/browse?fdfilter=search+query
                query = UriCompat.getQueryParameter(data, "fdfilter");

                // http://f-droid.org/repository/browse?fdid=packageName
                packageName = UriCompat.getQueryParameter(data, "fdid");
            } else if (path.startsWith("/app")) {
                // http://f-droid.org/app/packageName
                packageName = data.getLastPathSegment();
                if ("app".equals(packageName)) {
                    packageName = null;
                }
            }
            break;
        case "details":
            // market://details?id=app.id
            packageName = UriCompat.getQueryParameter(data, "id");
            break;
        case "search":
            // market://search?q=query
            query = UriCompat.getQueryParameter(data, "q");
            break;
        case "play.google.com":
            if (path.startsWith("/store/apps/details")) {
                // http://play.google.com/store/apps/details?id=app.id
                packageName = UriCompat.getQueryParameter(data, "id");
            } else if (path.startsWith("/store/search")) {
                // http://play.google.com/store/search?q=foo
                query = UriCompat.getQueryParameter(data, "q");
            }
            break;
        case "apps":
        case "amazon.com":
        case "www.amazon.com":
            // amzn://apps/android?p=app.id
            // http://amazon.com/gp/mas/dl/android?s=app.id
            packageName = UriCompat.getQueryParameter(data, "p");
            query = UriCompat.getQueryParameter(data, "s");
            break;
        }
    } else if ("fdroid.app".equals(scheme)) {
        // fdroid.app:app.id
        packageName = data.getSchemeSpecificPart();
    } else if ("fdroid.search".equals(scheme)) {
        // fdroid.search:query
        query = data.getSchemeSpecificPart();
    }

    if (!TextUtils.isEmpty(query)) {
        // an old format for querying via packageName
        if (query.startsWith("pname:"))
            packageName = query.split(":")[1];

        // sometimes, search URLs include pub: or other things before the query string
        if (query.contains(":"))
            query = query.split(":")[1];
    }

    if (!TextUtils.isEmpty(packageName)) {
        Utils.debugLog(TAG, "FDroid launched via app link for '" + packageName + "'");
        Intent intentToInvoke = new Intent(this, AppDetails.class);
        intentToInvoke.putExtra(AppDetails.EXTRA_APPID, packageName);
        startActivity(intentToInvoke);
    } else if (!TextUtils.isEmpty(query)) {
        Utils.debugLog(TAG, "FDroid launched via search link for '" + query + "'");
        performSearch(query);
    }
}

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

void processFiles() {
    // Check the amount of files we received in this transfer;
    // If more than one, create a separate directory for it.
    String extRoot = Environment.getExternalStorageDirectory().getPath();
    File beamPath = new File(extRoot + "/" + BEAM_DIR);

    if (!checkMediaStorage(beamPath) || mUris.size() == 0) {
        Log.e(TAG, "Media storage not valid or no uris received.");
        updateStateAndNotification(STATE_FAILED);
        return;/* www  .  j a va  2 s . c  om*/
    }

    if (mUris.size() > 1) {
        beamPath = generateMultiplePath(extRoot + "/" + BEAM_DIR + "/");
        if (!beamPath.isDirectory() && !beamPath.mkdir()) {
            Log.e(TAG, "Failed to create multiple path " + beamPath.toString());
            updateStateAndNotification(STATE_FAILED);
            return;
        }
    }

    for (int i = 0; i < mUris.size(); i++) {
        Uri uri = mUris.get(i);
        String mimeType = mTransferMimeTypes.get(i);

        File srcFile = new File(uri.getPath());

        File dstFile = generateUniqueDestination(beamPath.getAbsolutePath(), uri.getLastPathSegment());
        Log.d(TAG, "Renaming from " + srcFile);
        if (!srcFile.renameTo(dstFile)) {
            if (DBG)
                Log.d(TAG, "Failed to rename from " + srcFile + " to " + dstFile);
            srcFile.delete();
            return;
        } else {
            mPaths.add(dstFile.getAbsolutePath());
            mMimeTypes.put(dstFile.getAbsolutePath(), mimeType);
            if (DBG)
                Log.d(TAG, "Did successful rename from " + srcFile + " to " + dstFile);
        }
    }

    // We can either add files to the media provider, or provide an ACTION_VIEW
    // intent to the file directly. We base this decision on the mime type
    // of the first file; if it's media the platform can deal with,
    // use the media provider, if it's something else, just launch an ACTION_VIEW
    // on the file.
    String mimeType = mMimeTypes.get(mPaths.get(0));
    if (mimeType.startsWith("image/") || mimeType.startsWith("video/") || mimeType.startsWith("audio/")) {
        String[] arrayPaths = new String[mPaths.size()];
        MediaScannerConnection.scanFile(mContext, mPaths.toArray(arrayPaths), null, this);
        updateStateAndNotification(STATE_W4_MEDIA_SCANNER);
    } else {
        // We're done.
        updateStateAndNotification(STATE_SUCCESS);
    }

}

From source file:com.brandroidtools.filemanager.activities.PickerActivity.java

private File getInitialDirectoryFromIntent(Intent intent) {
    if (!Intent.ACTION_PICK.equals(intent.getAction())) {
        return null;
    }//from  w  w w .  jav a2s .  c o  m

    final Uri data = intent.getData();
    if (data == null) {
        return null;
    }

    final String path = data.getPath();
    if (path == null) {
        return null;
    }

    final File file = new File(path);
    if (!file.exists() || !file.isAbsolute()) {
        return null;
    }

    if (file.isDirectory()) {
        return file;
    }
    return file.getParentFile();
}

From source file:com.kanedias.vanilla.audiotag.PluginService.java

/**
 * Loads file as {@link AudioFile} and performs initial tag creation if it's absent.
 * If error happens while loading, shows popup indicating error details.
 * @return true if and only if file was successfully read and initialized in tag system, false otherwise
 *//*  w  w w .  j ava2 s .co m*/
public boolean loadFile(boolean force) {
    if (!force && mTag != null) {
        return true; // don't reload same file
    }

    // we need only path passed to us
    Uri fileUri = mLaunchIntent.getParcelableExtra(EXTRA_PARAM_URI);
    if (fileUri == null) {
        return false;
    }

    File file = new File(fileUri.getPath());
    if (!file.exists()) {
        return false;
    }

    try {
        mAudioFile = AudioFileIO.read(file);
        mTag = mAudioFile.getTagOrCreateAndSetDefault();
    } catch (CannotReadException | IOException | TagException | ReadOnlyFileException
            | InvalidAudioFrameException e) {
        Log.e(LOG_TAG, String.format(getString(R.string.error_audio_file), file.getAbsolutePath()), e);
        Toast.makeText(this, String.format(getString(R.string.error_audio_file) + ", %s",
                file.getAbsolutePath(), e.getLocalizedMessage()), Toast.LENGTH_SHORT).show();
        return false;
    }

    return true;
}

From source file:com.sandklef.coachapp.activities.TopActivity.java

private void saveMedia(Uri uri) {
    String club = LocalStorage.getInstance().getCurrentClub();
    String team = LocalStorage.getInstance().getCurrentTeam();
    String member = LocalStorage.getInstance().getCurrentMember();
    String tp = LocalStorage.getInstance().getCurrentTrainingPhase();
    // TODO: get member name instaed of UUID
    Storage.getInstance().log("Recorded " + member.toString(), "");
    Media m = new Media(null, "", club, uri.getPath(), Media.MEDIA_STATUS_NEW, System.currentTimeMillis(), team,
            tp, member);/*  www . j  av a  2 s .  c  om*/

    Log.d(LOG_TAG, "Calling storage to store Media.  File: " + uri.getPath());
    Storage.getInstance().saveMedia(m);
}

From source file:com.odoo.base.ir.Attachment.java

@SuppressWarnings("deprecation")
private Notification setFileIntent(Uri uri) {
    Log.v(TAG, "setFileIntent()");
    Intent intent = new Intent(Intent.ACTION_VIEW);
    FileNameMap mime = URLConnection.getFileNameMap();
    String mimeType = mime.getContentTypeFor(uri.getPath());
    intent.setDataAndType(uri, mimeType);
    mNotificationResultIntent = PendingIntent.getActivity(mContext, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mNotificationBuilder.addAction(R.drawable.ic_odoo_o, "Download attachment", mNotificationResultIntent);
    mNotificationBuilder.setOngoing(false);
    mNotificationBuilder.setAutoCancel(true);
    mNotificationBuilder.setContentTitle("Attachment downloaded");
    mNotificationBuilder.setContentText("Download Complete");
    mNotificationBuilder.setProgress(0, 0, false);
    mNotification = mNotificationBuilder.build();
    mNotification.setLatestEventInfo(mContext, "Attachment downloaded", "Download complete",
            mNotificationResultIntent);/*from  w  w w . ja  va  2 s .c o m*/
    return mNotification;

}

From source file:com.bilibili.boxing.AbsBoxingViewFragment.java

/**
 * successfully get result from crop in {@link #onActivityResult(int, int, Intent)}
 *//*from  w ww.j av  a 2 s  . c om*/
public void onCropActivityResult(int requestCode, int resultCode, @NonNull Intent data) {
    Uri output = BoxingCrop.getInstance().onCropFinish(resultCode, data);
    if (output != null) {
        List<BaseMedia> medias = new ArrayList<>(1);
        ImageMedia media = new ImageMedia(String.valueOf(System.currentTimeMillis()), output.getPath());
        medias.add(media);
        onFinish(medias);
    }
}

From source file:com.polyvi.xface.extension.XAppExt.java

private void setDirPermisionUntilWorkspace(XIWebContext webContext, Uri uri) {
    // ??//from  w w  w.j a  v  a 2s  .c  o  m
    // ?:?workspace
    if (!XConstant.FILE_SCHEME.contains(uri.getScheme())) {
        return;
    }
    String filePath = uri.getPath();
    String workspace = new File(webContext.getWorkSpace()).getAbsolutePath();
    File fileObj = new File(filePath);
    do {
        String path = fileObj.getAbsolutePath();
        // ??
        XFileUtils.setPermission(XFileUtils.ALL_PERMISSION, path);
        fileObj = new File(fileObj.getParent());
    } while (!fileObj.getAbsolutePath().equals(workspace));
}

From source file:com.ferdi2005.secondgram.AndroidUtilities.java

public static boolean isInternalUri(Uri uri) {
    String pathString = uri.getPath();
    if (pathString == null) {
        return false;
    }/*w  w  w . java  2  s  .c o  m*/
    while (true) {
        String newPath = Utilities.readlink(pathString);
        if (newPath == null || newPath.equals(pathString)) {
            break;
        }
        pathString = newPath;
    }
    if (pathString != null) {
        try {
            String path = new File(pathString).getCanonicalPath();
            if (path != null) {
                pathString = path;
            }
        } catch (Exception e) {
            pathString.replace("/./", "/");
            //igonre
        }
    }
    return pathString != null && pathString.toLowerCase()
            .contains("/data/data/" + ApplicationLoader.applicationContext.getPackageName() + "/files");
}

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

public void handleDuplicatedImage(Context context) {
    /*/* ww w  . j  a  v a  2s. com*/
     * Checking for duplicated images
     * This is necessary because some camera App implementation not only save image where 
     * you want them to save, but also in their App default location.
     */
    int lastContentId = getLastCapturedImageId(context);
    if (lastContentId == 0)
        return;

    Cursor imageCursor = UtilImage.getImageContentCursorByContentId(context, lastContentId);

    // New file: file1
    String path1 = null;
    File file1 = null;
    long dateTaken = 0;
    if (imageCursor.getCount() > 0) {
        imageCursor.moveToFirst(); // newest one
        path1 = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
        dateTaken = imageCursor.getLong(imageCursor.getColumnIndex(MediaStore.Images.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("imageCursor.getCount() = " + imageCursor.getCount());

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

    // Last file: file2
    Uri uri = Uri.parse(imageUriInDB);
    File file2 = new File(uri.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) // for Before Kitkat
        {
            System.out.println("deleted file path1 = " + path1);

            // delete 
            int deletedRows = context.getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    MediaStore.Images.ImageColumns.DATA + "='" + path1 + "'", null);

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

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

                // update new Uri to DB
                imageUriInDB = "file://" + Uri.parse(file1.getPath()).toString();
                if (!UtilImage.bShowExpandedImage)
                    noteId = savePictureStateInDB(noteId, imageUriInDB);

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

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

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