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:fr.enseirb.odroidx.videomanager.Uploader.java

public void doUpload(Uri myFile) {
    createNotification();/*w w  w . j  a v a 2  s . c o  m*/
    File f = new File(myFile.getPath());
    SendName(f.getName().replace(' ', '-'));
    Log.e(getClass().getSimpleName(), "test: " + f.exists());
    if (f.exists()) {
        Socket s;
        try {
            Log.e(getClass().getSimpleName(), "test: " + server_ip);
            s = new Socket(InetAddress.getByName(server_ip), 5088);// Bug
            // using
            // variable
            // port
            OutputStream fluxsortie = s.getOutputStream();
            int nb_parts = (int) (f.length() / PART_SIZE);

            InputStream in = new BufferedInputStream(new FileInputStream(f));
            ByteArrayOutputStream byte_array = new ByteArrayOutputStream();
            BufferedOutputStream buffer = new BufferedOutputStream(byte_array);

            byte[] to_write = new byte[PART_SIZE];
            for (int i = 0; i < nb_parts; i++) {
                in.read(to_write, 0, PART_SIZE);
                buffer.write(to_write);
                buffer.flush();
                fluxsortie.write(byte_array.toByteArray());
                byte_array.reset();
                if ((i % 250) == 0) {
                    mBuilder.setProgress(nb_parts, i, false);
                    mNotifyManager.notify(NOTIFY_ID, mBuilder.getNotification());
                }
            }
            int remaining = (int) (f.length() - nb_parts * PART_SIZE);
            in.read(to_write, 0, remaining);
            buffer.write(to_write);
            buffer.flush();
            fluxsortie.write(byte_array.toByteArray());
            byte_array.reset();
            buffer.close();
            fluxsortie.close();
            in.close();
            s.close();
        } catch (ConnectException e) {
            if (STATUS != HTTP_SERVER)
                STATUS = CONNECTION_ERROR;
            e.printStackTrace();
        } catch (UnknownHostException e) {
            if (STATUS != HTTP_SERVER)
                STATUS = UNKNOWN;
            Log.i(getClass().getSimpleName(), "Unknown host");
            e.printStackTrace();
        } catch (IOException e) {
            if (STATUS != HTTP_SERVER)
                STATUS = CONNECTION_ERROR;
            e.printStackTrace();
        }
    }
}

From source file:com.deliciousdroid.fragment.MainSearchResultsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    base = (FragmentBaseActivity) getActivity();
    base.setTitle(R.string.main_search_results_title);

    String[] MENU_ITEMS = new String[] { getString(R.string.search_results_bookmark),
            getString(R.string.search_results_tag), getString(R.string.search_results_global_tag) };

    setListAdapter(new ArrayAdapter<String>(base, R.layout.main_view, MENU_ITEMS));

    final Intent intent = base.getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (intent.hasExtra(SearchManager.QUERY)) {
            Intent i = new Intent(base, MainSearchResultsFragment.class);
            i.putExtras(intent.getExtras());
            startActivity(i);//from  ww  w .j av a2s . co  m
            base.finish();
        } else {
            base.onSearchRequested();
        }
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        Uri data = intent.getData();
        String path = null;
        String tagname = null;

        if (data != null) {
            path = data.getPath();
            tagname = data.getQueryParameter("tagname");
        }

        if (data.getScheme() == null || !data.getScheme().equals("content")) {
            Intent i = new Intent(Intent.ACTION_VIEW, data);

            startActivity(i);
            base.finish();
        } else if (path.contains("bookmarks") && TextUtils.isDigitsOnly(data.getLastPathSegment())) {
            Intent viewBookmark = new Intent(base, ViewBookmark.class);
            viewBookmark.setData(data);

            Log.d("View Bookmark Uri", data.toString());
            startActivity(viewBookmark);
            base.finish();
        } else if (tagname != null) {
            Intent viewTags = new Intent(base, BrowseBookmarks.class);
            viewTags.setData(data);

            Log.d("View Tags Uri", data.toString());
            startActivity(viewTags);
            base.finish();
        }
    }

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                searchActionListener.onBookmarkSearch();
            } else if (position == 1) {
                searchActionListener.onTagSearch();
            } else if (position == 2) {
                searchActionListener.onGlobalTagSearch();
            }
        }
    });
}

From source file:fr.simon.marquis.secretcodes.util.ExportContentProvider.java

@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
    if (!CONTENT_URI.equals(uri)) {
        throw new FileNotFoundException(uri.getPath());
    }//from ww  w  . j  ava 2  s.c om

    ArrayList<SecretCode> secretCodes = Utils.getSecretCodes(getContext());

    deletePreviousData();
    saveJsonFile(secretCodes);
    saveImageFiles(secretCodes);
    saveZipFile();

    File zipFile = new File(getContext().getFilesDir(), ZIP_FILE_NAME);
    if (zipFile.exists()) {
        return ParcelFileDescriptor.open(zipFile, ParcelFileDescriptor.MODE_READ_ONLY);
    }
    throw new FileNotFoundException(uri.getPath());
}

From source file:com.amytech.android.library.views.imagechooser.api.BChooser.java

/**
 * Utility method which quickly looks up the file size. Use this, if you want to set a limit to
 * the media chosen, and which your application can safely handle.
 * <p/>//from   ww w  .  j a  v a2 s.c o  m
 * For example, you might not want a video of 1 GB to be imported into your app.
 *
 * @param uri
 * @param context
 * @return
 */
public long queryProbableFileSize(Uri uri, Context context) {
    try {
        if (uri.toString().startsWith("file")) {
            File file = new File(uri.getPath());
            return file.length();
        } else if (uri.toString().startsWith("content")) {
            Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
            cursor.moveToFirst();
            long length = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
            cursor.close();
            return length;
        }
        return 0;
    } catch (Exception e) {
        return 0;
    }
}

From source file:com.codebutler.farebot.fragments.CardsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    try {//ww  w . ja va  2 s . c om
        if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_SELECT_FILE) {
            Uri uri = data.getData();
            String xml = org.apache.commons.io.FileUtils.readFileToString(new File(uri.getPath()));
            onCardsImported(ExportHelper.importCardsXml(getActivity(), xml));
        }
    } catch (Exception ex) {
        Utils.showError(getActivity(), ex);
    }
}

From source file:com.kentdisplays.synccardboarddemo.FileDownloadService.java

@Override
public void onChangeFolderComplete(Uri uri, int result) {
    if (result == SyncFtpService.RESULT_OK) {
        // Changed to the root folder.
        if (uri.getPath().equals("/")) {
            navigateToSavedFolder();/*from www  .ja va 2  s.c o  m*/
        }

        // Changed to the SAVED folder.
        else if (uri.getPath().contains("SAVED")) {
            mFtpService.listFolder();
        }
    } else {
        stopDownload();
    }
}

From source file:com.Jsu.framework.image.imageChooser.BChooser.java

/**
 * Utility method which quickly looks up the file size. Use this, if you want to set a limit to
 * the media chosen, and which your application can safely handle.
 * <p/>//  w ww  .j  a  v a 2s.c  om
 * For example, you might not want a video of 1 GB to be imported into your app.
 *
 * @param uri
 * @param context
 * @return
 */
public long queryProbableFileSize(Uri uri, Context context) {

    if (uri.toString().startsWith("file")) {
        File file = new File(uri.getPath());
        return file.length();
    } else if (uri.toString().startsWith("content")) {
        Cursor cursor = null;
        try {
            cursor = context.getContentResolver().query(uri, null, null, null, null);
            StreamHelper.verifyCursor(uri, cursor);
            if (cursor.moveToFirst()) {
                return cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
            }
            return 0;
        } catch (ChooserException e) {
            return 0;
        } finally {
            StreamHelper.closeSilent(cursor);
        }
    }

    return 0;
}

From source file:com.kbeanie.imagechooser.api.BChooser.java

/**
 * Utility method which quickly looks up the file size. Use this, if you want to set a limit to
 * the media chosen, and which your application can safely handle.
 * <p/>/*from w  w w .j  a  v  a 2  s  . co m*/
 * For example, you might not want a video of 1 GB to be imported into your app.
 *
 * @param uri
 * @param context
 * @return
 */
public long queryProbableFileSize(Uri uri, Context context) {

    if (uri.toString().startsWith("file")) {
        File file = new File(uri.getPath());
        return file.length();
    } else if (uri.toString().startsWith("content")) {
        Cursor cursor = null;
        try {
            cursor = context.getContentResolver().query(uri, null, null, null, null);
            verifyCursor(uri, cursor);
            if (cursor.moveToFirst()) {
                return cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
            }
            return 0;
        } catch (ChooserException e) {
            return 0;
        } finally {
            closeSilent(cursor);
        }
    }

    return 0;
}

From source file:com.commonsware.android.documents.consumer.DurablizerService.java

private DocumentFile buildDocFileForUri(Uri document) {
    DocumentFile docFile;/*ww  w  .  j  av a 2 s  .c  o m*/

    if (document.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
        docFile = DocumentFile.fromSingleUri(this, document);
    } else {
        docFile = DocumentFile.fromFile(new File(document.getPath()));
    }

    return (docFile);
}

From source file:edu.stanford.mobisocial.dungbeetle.obj.action.RelatedObjAction.java

@Override
public void onAct(Context context, DbEntryHandler objType, DbObj obj) {
    Uri feedUri = obj.getContainingFeed().getUri();
    long hash = obj.getHash();
    // TODO:/*from  w  ww .j  a v  a  2  s . c  o  m*/
    /*Intent viewComments = new Intent(Intent.ACTION_VIEW);
    viewComments.setDataAndType(objUri, DbObject.MIME_TYPE);
    mmContext.startActivity(viewComments);*/
    Uri objUri = feedUri.buildUpon().encodedPath(feedUri.getPath() + ":" + hash).build();

    Intent objViewActivity = new Intent(Intent.ACTION_VIEW);
    objViewActivity.setDataAndType(objUri, Feed.MIME_TYPE);
    context.startActivity(objViewActivity);
}