List of usage examples for android.net Uri getPath
@Nullable public abstract String getPath();
From source file:com.remobile.file.LocalFilesystem.java
@Override public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName, Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException { // Check to see if the destination directory exists String newParent = this.filesystemPathForURL(destURL); File destinationDir = new File(newParent); if (!destinationDir.exists()) { // The destination does not exist so we should fail. throw new FileNotFoundException("The source does not exist"); }/*from w ww . j a va2s . c o m*/ // Figure out where we should be copying to final LocalFilesystemURL destinationURL = makeDestinationURL(newName, srcURL, destURL, srcURL.isDirectory); Uri dstNativeUri = toNativeUri(destinationURL); Uri srcNativeUri = srcFs.toNativeUri(srcURL); // Check to see if source and destination are the same file if (dstNativeUri.equals(srcNativeUri)) { throw new InvalidModificationException("Can't copy onto itself"); } if (move && !srcFs.canRemoveFileAtLocalURL(srcURL)) { throw new InvalidModificationException("Source URL is read-only (cannot move)"); } File destFile = new File(dstNativeUri.getPath()); if (destFile.exists()) { if (!srcURL.isDirectory && destFile.isDirectory()) { throw new InvalidModificationException("Can't copy/move a file to an existing directory"); } else if (srcURL.isDirectory && destFile.isFile()) { throw new InvalidModificationException("Can't copy/move a directory to an existing file"); } } if (srcURL.isDirectory) { // E.g. Copy /sdcard/myDir to /sdcard/myDir/backup if (dstNativeUri.toString().startsWith(srcNativeUri.toString() + '/')) { throw new InvalidModificationException("Can't copy directory into itself"); } copyDirectory(srcFs, srcURL, destFile, move); } else { copyFile(srcFs, srcURL, destFile, move); } return makeEntryForURL(destinationURL); }
From source file:de.ub0r.android.callmeter.ui.prefs.Preferences.java
/** * Get a {@link InputStream} from {@link Uri}. * //from w ww. j ava 2 s. c om * @param cr * {@link ContentResolver} * @param uri * {@link Uri} * @return {@link InputStream} */ private InputStream getStream(final ContentResolver cr, final Uri uri) { if (uri.toString().startsWith("import")) { String url; if (uri.getScheme().equals("imports")) { url = "https:/"; } else { url = "http:/"; } url += uri.getPath(); final HttpGet request = new HttpGet(url); Log.d(TAG, "url: " + url); try { final HttpResponse response = new DefaultHttpClient().execute(request); int resp = response.getStatusLine().getStatusCode(); if (resp != HttpStatus.SC_OK) { return null; } return response.getEntity().getContent(); } catch (IOException e) { Log.e(TAG, "error in reading export: " + url, e); return null; } } else if (uri.toString().startsWith("content://") || uri.toString().startsWith("file://")) { try { return cr.openInputStream(uri); } catch (IOException e) { Log.e(TAG, "error in reading export: " + uri.toString(), e); return null; } } Log.d(TAG, "getStream() returns null, " + uri.toString()); return null; }
From source file:com.freeme.filemanager.FileExplorerTabActivity.java
@Override protected void onNewIntent(Intent paramIntent) { // TODO Auto-generated method stub super.onNewIntent(paramIntent); setIntent(paramIntent);/*w ww . j a v a 2 s .c o m*/ Uri pathUri = paramIntent.getData(); if ((pathUri != null) && (!TextUtils.isEmpty(pathUri.getPath()))) { ((FileViewFragment) this.mTabsAdapter.getItem(1)).setPath(pathUri.getPath()); return; } }
From source file:com.slim.turboeditor.activity.MainActivity.java
/** * Parses the intent//from w w w . j a va 2 s . c om */ private void parseIntent(Intent intent) { final String action = intent.getAction(); final String type = intent.getType(); if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action) || Intent.ACTION_PICK.equals(action) && type != null) { Uri uri = intent.getData(); File newFile = new File(uri.getPath()); newFileToOpen(newFile, ""); } else if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { newFileToOpen(null, intent.getStringExtra(Intent.EXTRA_TEXT)); } } }
From source file:com.bitants.wally.activities.ImageDetailsActivity.java
private void handleSavedImageData(Uri filePath) { if (filePath != null && filePath.getPath() != null) { Message msgObj = uiHandler.obtainMessage(); msgObj.what = currentHandlerCode; msgObj.obj = filePath;//from w w w . j a va 2s . c o m uiHandler.sendMessage(msgObj); MediaScannerConnection.scanFile(getApplicationContext(), new String[] { filePath.getPath() }, null, new MediaScannerConnection.MediaScannerConnectionClient() { @Override public void onMediaScannerConnected() { } @Override public void onScanCompleted(String path, Uri uri) { getApplication().sendBroadcast(new Intent(FileReceiver.GET_FILES)); } }); } }
From source file:ch.luklanis.esscan.history.HistoryActivity.java
private Uri createDTAFile(long bankProfileId) { List<HistoryItem> historyItems = mHistoryManager.buildHistoryItemsForDTA(bankProfileId); BankProfile bankProfile = mHistoryManager.getBankProfile(bankProfileId); String error = dtaFileCreator.getFirstError(bankProfile, historyItems); if (!TextUtils.isEmpty(error)) { setOkAlert(error);/*from www . j av a 2 s . com*/ return null; } CharSequence dta = dtaFileCreator.buildDTA(bankProfile, historyItems); if (!dtaFileCreator.saveDTAFile(dta.toString())) { setOkAlert(R.string.msg_unmount_usb); return null; } else { Uri dtaFileUri = dtaFileCreator.getDTAFileUri(); String dtaFileName = dtaFileUri.getLastPathSegment(); new HistoryExportUpdateAsyncTask(mHistoryManager, dtaFileName) .execute(historyItems.toArray(new HistoryItem[historyItems.size()])); this.dtaFileCreator = new DTAFileCreator(getApplicationContext()); Toast toast = Toast.makeText(this, getResources().getString(R.string.msg_dta_saved, dtaFileUri.getPath()), Toast.LENGTH_LONG); toast.setGravity(Gravity.BOTTOM, 0, 0); toast.show(); return dtaFileUri; } }
From source file:mobisocial.musubi.util.UriImage.java
private InputStream openInputStream(Uri uri) throws IOException { String scheme = uri.getScheme(); if ("content".equals(scheme)) { return mContext.getContentResolver().openInputStream(mUri); } else if (scheme.startsWith("http")) { if (mByteCache == null) { DefaultHttpClient c = new DefaultHttpClient(); HttpGet get = new HttpGet(uri.toString()); HttpResponse response = c.execute(get); mByteCache = IOUtils.toByteArray(response.getEntity().getContent()); }/*from w w w . j a va2s .c o m*/ return new ByteArrayInputStream(mByteCache); } else if (scheme.equals("file")) { return new FileInputStream(uri.getPath()); } else { throw new IOException("Unmatched uri scheme " + scheme); } }
From source file:edu.mit.mobile.android.locast.data.MediaSync.java
/** * Synchronize the media of the given castMedia. It will download or upload * as needed./*from w w w. j a v a 2 s.c om*/ * * @param castMediaUri * @throws SyncException */ public void syncItemMedia(Uri castMediaUri) throws SyncException { final Cursor castMedia = cr.query(castMediaUri, PROJECTION, null, null, null); final Uri castUri = CastMedia.getCast(castMediaUri); final Cursor cast = cr.query(castUri, CAST_PROJECTION, null, null, null); try { if (!castMedia.moveToFirst()) { throw new IllegalArgumentException("uri " + castMediaUri + " has no content"); } if (!cast.moveToFirst()) { throw new IllegalArgumentException(castMediaUri + " cast " + castUri + " has no content"); } // cache the column numbers final int mediaUrlCol = castMedia.getColumnIndex(CastMedia._MEDIA_URL); final int localUriCol = castMedia.getColumnIndex(CastMedia._LOCAL_URI); final boolean isFavorite = cast.getInt(cast.getColumnIndex(Cast._FAVORITED)) != 0; final boolean keepOffline = castMedia.getInt(castMedia.getColumnIndex(CastMedia._KEEP_OFFLINE)) != 0; final String mimeType = castMedia.getString(castMedia.getColumnIndex(CastMedia._MIME_TYPE)); final boolean isImage = (mimeType != null) && mimeType.startsWith("image/"); // we don't need to sync this if ("text/html".equals(mimeType)) { return; } final Uri locMedia = castMedia.isNull(localUriCol) ? null : Uri.parse(castMedia.getString(localUriCol)); final String pubMedia = castMedia.getString(mediaUrlCol); final boolean hasLocMedia = locMedia != null && new File(locMedia.getPath()).exists(); final boolean hasPubMedia = pubMedia != null && pubMedia.length() > 0; final String localThumb = castMedia.getString(castMedia.getColumnIndex(CastMedia._THUMB_LOCAL)); if (hasLocMedia && !hasPubMedia) { final String uploadPath = castMedia.getString(castMedia.getColumnIndex(CastMedia._PUBLIC_URI)); uploadMedia(uploadPath, castMediaUri, mimeType, locMedia); } else if (!hasLocMedia && hasPubMedia) { // only have a public copy, so download it and store locally. final Uri pubMediaUri = Uri.parse(pubMedia); final File destfile = getFilePath(pubMediaUri); // the following conditions indicate that the cast media should be downloaded. if (keepOffline || isFavorite) { final boolean anythingChanged = downloadMediaFile(pubMedia, destfile, castMediaUri); // the below is inverted from what seems logical, because downloadMediaFile() // will actually update the castmedia if it downloads anything. We'll only be getting // here if we don't have any local record of the file, so we should make the association // by ourselves. if (!anythingChanged) { File thumb = null; if (isImage && localThumb == null) { thumb = destfile; } updateLocalFile(castMediaUri, destfile, thumb); // disabled to avoid spamming the user with downloaded // items. // checkForMediaEntry(castMediaUri, pubMediaUri, mimeType); } } } } finally { cast.close(); castMedia.close(); } }
From source file:com.appbase.androidquery.callback.AbstractAjaxCallback.java
private static String extractUrl(Uri uri) { String result = uri.getScheme() + "://" + uri.getAuthority() + uri.getPath(); String fragment = uri.getFragment(); if (fragment != null) result += "#" + fragment; return result; }
From source file:com.slim.turboeditor.activity.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, final Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK) { if (requestCode == SELECT_FILE_CODE) { final Uri data = intent.getData(); File newFile = new File(data.getPath()); newFileToOpen(newFile, ""); } else {/*www. j a va 2 s . c om*/ final Uri data = intent.getData(); final File newFile = new File(data.getPath()); // grantUriPermission(getPackageName(), // data, Intent.FLAG_GRANT_READ_URI_PERMISSION); // Check for the freshest data. getContentResolver().takePersistableUriPermission(data, (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)); if (requestCode == READ_REQUEST_CODE || requestCode == CREATE_REQUEST_CODE) { newFileToOpen(newFile, ""); } if (requestCode == SAVE_AS_REQUEST_CODE) { getSaveFileObservable(getApplicationContext(), newFile, pageSystem.getAllText(mEditor.getText().toString()), currentEncoding) .subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<Boolean>() { @Override public void call(Boolean aBoolean) { savedAFile(aBoolean); newFileToOpen(newFile, ""); } }); } } } }