List of usage examples for android.content ContentResolver SCHEME_FILE
String SCHEME_FILE
To view the source code for android.content ContentResolver SCHEME_FILE.
Click Source Link
From source file:com.commonsware.android.tte.MainActivity.java
private void openEditor(Uri document) { if (ContentResolver.SCHEME_CONTENT.equals(document.getScheme()) || canWriteFiles()) { int position = adapter.getPositionForDocument(document); if (position == -1) { adapter.addDocument(document); pager.setCurrentItem(adapter.getCount() - 1); if (!editHistory.addOpenEditor(document)) { Toast.makeText(this, R.string.msg_save_history, Toast.LENGTH_LONG).show(); }/*from w w w . j a v a2 s. co m*/ } else { pager.setCurrentItem(position); } } else if (ContentResolver.SCHEME_FILE.equals(document.getScheme())) { pendingFiles.add(document); ActivityCompat.requestPermissions(this, PERMS_FILE, REQUEST_PERMS_FILE); } }
From source file:com.owncloud.android.datamodel.OCFile.java
/** * The URI to the file contents, if stored locally * * @return A URI to the local copy of the file, or NULL if not stored in the device */// www . j a v a2 s. c o m public Uri getStorageUri() { if (mLocalPath == null || mLocalPath.length() == 0) { return null; } if (mLocalUri == null) { Uri.Builder builder = new Uri.Builder(); builder.scheme(ContentResolver.SCHEME_FILE); builder.path(mLocalPath); mLocalUri = builder.build(); } return mLocalUri; }
From source file:net.sourceforge.fidocadj.FidoMain.java
/** Inspired from // ww w . jav a2 s. co m http://richardleggett.co.uk/blog/2013/01/26/ registering_for_file_types_in_android/ detects if in the data there is a file indication, open it and load its contents. @return true if something has been loaded, false otherwise */ private boolean importData(Uri data) { final String scheme = data.getScheme(); // Check wether there is a file in the data provided. if (ContentResolver.SCHEME_FILE.equals(scheme)) { try { ContentResolver cr = getContentResolver(); InputStream is = cr.openInputStream(data); if (is == null) return false; // Read the contents of the file. StringBuffer buf = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String str; if (is != null) { while ((str = reader.readLine()) != null) { buf.append(str + "\n"); } } is.close(); return true; } catch (Exception e) { Log.e("fidocadj", "FidoMain.ImportData, Error reading file: " + e.toString()); } } return false; }
From source file:com.android.emailcommon.utility.AttachmentUtilities.java
/** * @return mime-type for a {@link Uri}.// w ww.ja v a 2s . c o m * - Use {@link ContentResolver#getType} for a content: URI. * - Use {@link #inferMimeType} for a file: URI. * - Otherwise returns null. */ public static String inferMimeTypeForUri(Context context, Uri uri) { final String scheme = uri.getScheme(); if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { return context.getContentResolver().getType(uri); } else if (ContentResolver.SCHEME_FILE.equals(scheme)) { return inferMimeType(uri.getLastPathSegment(), ""); } else { Log.e(Logging.LOG_TAG, "Unable to determine MIME type for uri=" + uri, new Error()); return null; } }
From source file:com.owncloud.android.datamodel.OCFile.java
public Uri getExposedFileUri(Context context) { if (mLocalPath == null || mLocalPath.length() == 0) { return null; }// w ww .j a v a 2 s . c o m if (mExposedFileUri == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { // TODO - use FileProvider with any Android version, with deeper testing -> 2.2.0 mExposedFileUri = Uri .parse(ContentResolver.SCHEME_FILE + "://" + WebdavUtils.encodePath(mLocalPath)); } else { // Use the FileProvider to get a content URI try { mExposedFileUri = FileProvider.getUriForFile(context, context.getString(R.string.file_provider_authority), new File(mLocalPath)); } catch (IllegalArgumentException e) { Log_OC.e(TAG, "File can't be exported"); } } } return mExposedFileUri; }
From source file:org.sufficientlysecure.keychain.ui.EncryptFilesFragment.java
/** * Request READ_EXTERNAL_STORAGE permission on Android >= 6.0 to read content from "file" Uris. * * This method returns true on Android < 6, or if permission is already granted. It * requests the permission and returns false otherwise. * * see https://commonsware.com/blog/2015/10/07/runtime-permissions-files-action-send.html *//* w w w .j a v a 2 s. c om*/ private boolean checkAndRequestReadPermission(final Uri uri) { if (!ContentResolver.SCHEME_FILE.equals(uri.getScheme())) { return true; } // Additional check due to https://commonsware.com/blog/2015/11/09/you-cannot-hold-nonexistent-permissions.html if (Build.VERSION.SDK_INT < VERSION_CODES.M) { return true; } if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { return true; } requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_PERMISSION_READ_EXTERNAL_STORAGE); return false; }
From source file:com.android.gallery3d.data.UriImage.java
private boolean isSharable() { // We cannot grant read permission to the receiver since we put // the data URI in EXTRA_STREAM instead of the data part of an intent // And there are issues in MediaUploader and Bluetooth file sender to // share a general image data. So, we only share for local file. return ContentResolver.SCHEME_FILE.equals(mUri.getScheme()); }
From source file:com.android.gallery3d.data.UriImage.java
@Override public MediaDetails getDetails() { MediaDetails details = super.getDetails(); if (mWidth != 0 && mHeight != 0) { details.addDetail(MediaDetails.INDEX_WIDTH, mWidth); details.addDetail(MediaDetails.INDEX_HEIGHT, mHeight); }/*from www . j a va2 s . c o m*/ if (mContentType != null) { details.addDetail(MediaDetails.INDEX_MIMETYPE, mContentType); } if (ContentResolver.SCHEME_FILE.equals(mUri.getScheme())) { String filePath = mUri.getPath(); details.addDetail(MediaDetails.INDEX_PATH, filePath); MediaDetails.extractExifInfo(details, filePath); } return details; }
From source file:org.sufficientlysecure.keychain.util.FileHelper.java
/** * Deletes data at a URI securely by overwriting it with random data * before deleting it. This method is fail-fast - if we can't securely * delete the file, we don't delete it at all. */// w w w . java2 s. co m public static int deleteFileSecurely(Context context, Uri uri) throws IOException { ContentResolver resolver = context.getContentResolver(); long lengthLeft = FileHelper.getFileSize(context, uri); if (lengthLeft == -1) { throw new IOException("Error opening file!"); } SecureRandom random = new SecureRandom(); byte[] randomData = new byte[1024]; OutputStream out = resolver.openOutputStream(uri, "w"); if (out == null) { throw new IOException("Error opening file!"); } out = new BufferedOutputStream(out); while (lengthLeft > 0) { random.nextBytes(randomData); out.write(randomData, 0, lengthLeft > randomData.length ? randomData.length : (int) lengthLeft); lengthLeft -= randomData.length; } out.close(); if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) { return new File(uri.getPath()).delete() ? 1 : 0; } else { return resolver.delete(uri, null, null); } }
From source file:com.jefftharris.passwdsafe.file.PasswdFileUri.java
/** Get the URI type */ private static Type getUriType(Uri uri) { if (uri.getScheme().equals(ContentResolver.SCHEME_FILE)) { return Type.FILE; }//from www. j ava 2 s . co m String auth = uri.getAuthority(); if (PasswdSafeContract.AUTHORITY.equals(auth)) { return Type.SYNC_PROVIDER; } else if (auth.contains("mail")) { return Type.EMAIL; } return Type.GENERIC_PROVIDER; }