List of usage examples for android.net Uri getPath
@Nullable public abstract String getPath();
From source file:br.com.brolam.cloudvision.ui.helpers.ImagesHelper.java
/** * Analisar e validar uma imagem de background para um Note Vision. * @param noteVisionKey/*from w w w . j a v a 2 s .c o m*/ * @return verdadeiro se a imagem for vlida. */ private boolean parseImageNoteVisionBackground(String noteVisionKey) { Uri imageUri = getImageUriFile(noteVisionKey); File imageFile = new File(imageUri.getPath()); if (imageFile.exists()) { //Reduzir o tamanho de imagens acima de 1MB. if (imageFile.getTotalSpace() > 1048576) { //Tentar reduzir o tamanho da imagem. try { resizeImage(imageUri.getPath(), noteVisionBackgroundWidth, noteVisionBackgroundHeight); } catch (IOException e) { e.printStackTrace(); } } else if (imageFile.getTotalSpace() == 0) { //Excluir a imagem se a mesma no for vlida. imageFile.delete(); return false; } return true; } ; return false; }
From source file:org.mobisocial.corral.ContentCorral.java
private static String getIndexPath(Uri uri) { String seg = uri.getLastPathSegment(); if (seg.endsWith(".html") || seg.endsWith(".htm") || seg.endsWith(".php")) { return uri.getPath(); }/*from w ww. j a v a2 s . co m*/ return uri.buildUpon().appendPath("index.html").build().getPath(); }
From source file:com.cyberocw.habittodosecretary.file.StorageHelper.java
/** * Create a path where we will place our private file on external *///from w w w . j av a2 s . c o m public static File createExternalStoragePrivateFile(Context mContext, Uri uri, String extension) { // Checks for external storage availability if (!checkStorage()) { Toast.makeText(mContext, "storage_not_available", Toast.LENGTH_SHORT).show(); return null; } // ? ? getExternalFilesDir File file = createNewAttachmentFile(mContext, extension); InputStream is = null; OutputStream os = null; try { is = mContext.getContentResolver().openInputStream(uri); os = new FileOutputStream(file); copyFile(is, os); } catch (IOException e) { try { is = new FileInputStream(FileHelper.getPath(mContext, uri)); os = new FileOutputStream(file); copyFile(is, os); // It's a path!! } catch (NullPointerException e1) { try { is = new FileInputStream(uri.getPath()); os = new FileOutputStream(file); copyFile(is, os); } catch (FileNotFoundException e2) { Log.e(Const.ERROR_TAG, "Error writing " + file, e2); file = null; } } catch (FileNotFoundException e2) { Log.e(Const.ERROR_TAG, "Error writing " + file, e2); file = null; } } finally { try { if (is != null) { is.close(); } if (os != null) { os.close(); } } catch (IOException e) { Log.e(Const.ERROR_TAG, "Error closing streams", e); } } return file; }
From source file:org.mobisocial.corral.CorralDownloadClient.java
Uri doMediaScan(Uri content) { String[] paths = new String[] { content.getPath() }; MediaScannerConnection.scanFile(mContext, paths, null, null); return content; }
From source file:br.com.bioscada.apps.biotracks.io.file.importer.ImportActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent();/*from w w w . j a v a2s . c o m*/ importAll = intent.getBooleanExtra(EXTRA_IMPORT_ALL, false); trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT); if (trackFileFormat == null) { trackFileFormat = TrackFileFormat.GPX; } if (!FileUtils.isExternalStorageAvailable()) { Toast.makeText(this, R.string.external_storage_not_available, Toast.LENGTH_LONG).show(); finish(); return; } String directoryPath; if (importAll) { directoryDisplayName = FileUtils.getPathDisplayName(trackFileFormat.getExtension()); directoryPath = FileUtils.getPath(trackFileFormat.getExtension()); if (!FileUtils.isDirectory(new File(directoryPath))) { Toast.makeText(this, getString(R.string.import_no_directory, directoryDisplayName), Toast.LENGTH_LONG).show(); finish(); return; } } else { String action = intent.getAction(); if (!(Intent.ACTION_ATTACH_DATA.equals(action) || Intent.ACTION_VIEW.equals(action))) { Log.d(TAG, "Invalid action: " + intent); finish(); return; } Uri data = intent.getData(); if (!UriUtils.isFileUri(data)) { Log.d(TAG, "Invalid data: " + intent); finish(); return; } directoryDisplayName = data.getPath(); directoryPath = data.getPath(); } Object retained = getLastNonConfigurationInstance(); if (retained instanceof ImportAsyncTask) { importAsyncTask = (ImportAsyncTask) retained; importAsyncTask.setActivity(this); } else { importAsyncTask = new ImportAsyncTask(this, importAll, trackFileFormat, directoryPath); importAsyncTask.execute(); } }
From source file:com.owncloud.android.lib.test_project.test.OwnCloudClientTest.java
public void testGetWebdavUri() { OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken")); Uri webdavUri = client.getWebdavUri(); assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " + "authenticated servers", webdavUri.getPath().endsWith(AccountUtils.ODAV_PATH)); assertTrue("WebDAV URI is not a subpath of base URI", webdavUri.getAuthority().equals(mServerUri.getAuthority()) && webdavUri.getPath().startsWith(mServerUri.getPath())); client.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials(mUsername, mPassword)); webdavUri = client.getWebdavUri();//from w ww . j a va 2 s. com assertTrue("WebDAV URI does not point to the right entry point", webdavUri.getPath().endsWith(AccountUtils.WEBDAV_PATH_4_0)); PropFindMethod propfind = null; try { propfind = new PropFindMethod(webdavUri + "/", DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_0); int status = client.executeMethod(propfind); assertEquals("WebDAV request did not work on WebDAV URI", HttpStatus.SC_MULTI_STATUS, status); } catch (IOException e) { Log.e(TAG, "Exception in PROPFIND method execution", e); // TODO - make it fail? ; try several times, and make it fail if none // is right? } finally { propfind.releaseConnection(); } }
From source file:ir.keloud.android.lib.test_project.test.KeloudClientTest.java
public void testGetWebdavUri() { KeloudClient client = new KeloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); client.setCredentials(KeloudCredentialsFactory.newBearerCredentials("fakeToken")); Uri webdavUri = client.getWebdavUri(); assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " + "authenticated servers", webdavUri.getPath().endsWith(AccountUtils.ODAV_PATH)); assertTrue("WebDAV URI is not a subpath of base URI", webdavUri.getAuthority().equals(mServerUri.getAuthority()) && webdavUri.getPath().startsWith(mServerUri.getPath())); client.setCredentials(KeloudCredentialsFactory.newBasicCredentials(mUsername, mPassword)); webdavUri = client.getWebdavUri();/*from ww w . j a va 2s. c om*/ assertTrue("WebDAV URI does not point to the right entry point", webdavUri.getPath().endsWith(AccountUtils.WEBDAV_PATH_4_0)); PropFindMethod propfind = null; try { propfind = new PropFindMethod(webdavUri + "/", DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_0); int status = client.executeMethod(propfind); assertEquals("WebDAV request did not work on WebDAV URI", HttpStatus.SC_MULTI_STATUS, status); } catch (IOException e) { Log.e(TAG, "Exception in PROPFIND method execution", e); // TODO - make it fail? ; try several times, and make it fail if none // is right? } finally { propfind.releaseConnection(); } }
From source file:com.ls.sip.CameraFragment.java
@SuppressWarnings({ "unused", "ConstantConditions" }) public void onEventMainThread(CameraEngine.VideoTakenEvent event) { if (event.exception == null) { if (getArguments().getBoolean(ARG_UPDATE_MEDIA_STORE, false)) { final Context app = getActivity().getApplicationContext(); Uri output = getArguments().getParcelable(ARG_OUTPUT); final String path = output.getPath(); new Thread() { @Override/*from w ww .java 2 s.c om*/ public void run() { SystemClock.sleep(2000); MediaScannerConnection.scanFile(app, new String[] { path }, new String[] { "video/mp4" }, null); } }.start(); } isVideoRecording = false; btnTakePicture.setImageResource(R.drawable.cwac_cam2_ic_videocam); } else { getActivity().finish(); } }
From source file:com.dycody.android.idealnote.utils.StorageHelper.java
/** * Create a path where we will place our private file on external * * @param mContext//from www . j av a 2s . c om * @param uri * @return */ public static File createExternalStoragePrivateFile(Context mContext, Uri uri, String extension) { // Checks for external storage availability if (!checkStorage()) { Toast.makeText(mContext, mContext.getString(com.dycody.android.idealnote.R.string.storage_not_available), Toast.LENGTH_SHORT).show(); return null; } File file = createNewAttachmentFile(mContext, extension); InputStream is; OutputStream os; try { is = mContext.getContentResolver().openInputStream(uri); os = new FileOutputStream(file); copyFile(is, os); } catch (IOException e) { try { is = new FileInputStream(FileHelper.getPath(mContext, uri)); os = new FileOutputStream(file); copyFile(is, os); // It's a path!! } catch (NullPointerException e1) { try { is = new FileInputStream(uri.getPath()); os = new FileOutputStream(file); copyFile(is, os); } catch (FileNotFoundException e2) { Log.e(Constants.TAG, "Error writing " + file, e2); file = null; } } catch (FileNotFoundException e2) { Log.e(Constants.TAG, "Error writing " + file, e2); file = null; } } return file; }
From source file:be.ppareit.swiftp.gui.PreferenceFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent resultData) { if (requestCode == ACTION_OPEN_DOCUMENT_TREE && resultCode == Activity.RESULT_OK) { Uri treeUri = resultData.getData(); String path = treeUri.getPath(); final CheckBoxPreference writeExternalStorage_pref = findPref("writeExternalStorage"); if (!":".equals(path.substring(path.length() - 1)) || path.contains("primary")) { writeExternalStorage_pref.setChecked(false); } else {//from w ww.j a v a 2 s . c o m FsSettings.setExternalStorageUri(treeUri.toString()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getActivity().getContentResolver().takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } writeExternalStorage_pref.setChecked(true); } } }