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.filemanager.free.activities.MainActivity.java
@Override public void onResume() { AdWrapper.viewAd(true, mainActivity); requestNewInterstitial();//from w ww.ja v a 2 s . c o m if (materialDialog != null && !materialDialog.isShowing()) { materialDialog.show(); materialDialog = null; } IntentFilter newFilter = new IntentFilter(); newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); newFilter.addDataScheme(ContentResolver.SCHEME_FILE); registerReceiver(mainActivityHelper.mNotificationReceiver, newFilter); registerReceiver(receiver2, new IntentFilter("general_communications")); if (getSupportFragmentManager().findFragmentById(R.id.content_frame).getClass().getName() .contains("TabFragment")) { floatingActionButton.setVisibility(View.VISIBLE); floatingActionButton.showMenuButton(false); } else { floatingActionButton.setVisibility(View.INVISIBLE); floatingActionButton.hideMenuButton(false); } super.onResume(); }
From source file:com.igniva.filemanager.activities.MainActivity.java
@Override public void onResume() { super.onResume(); if (materialDialog != null && !materialDialog.isShowing()) { materialDialog.show();//w w w . ja va2 s . c o m materialDialog = null; } IntentFilter newFilter = new IntentFilter(); newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); newFilter.addDataScheme(ContentResolver.SCHEME_FILE); registerReceiver(mainActivityHelper.mNotificationReceiver, newFilter); registerReceiver(receiver2, new IntentFilter("general_communications")); if (getSupportFragmentManager().findFragmentById(R.id.content_frame).getClass().getName() .contains("TabFragment")) { floatingActionButton.setVisibility(View.VISIBLE); floatingActionButton.showMenuButton(false); } else { floatingActionButton.setVisibility(View.INVISIBLE); floatingActionButton.hideMenuButton(false); } // Registering intent filter for OTG IntentFilter otgFilter = new IntentFilter(); otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); }
From source file:com.ubuntuone.android.files.activity.FilesActivity.java
private void onFileClicked(final String resourcePath, final String resourceState, final String filename, final String data) { Log.d(TAG, "onFileClicked() data=" + data); final boolean isStateIdle = (resourceState == null); boolean isDownloading, isFailedDownload; isDownloading = isFailedDownload = false; if (!isStateIdle) { isDownloading = ResourceState.STATE_GETTING.equals(resourceState); isFailedDownload = ResourceState.STATE_GETTING_FAILED.equals(resourceState); }/*from w ww.j a v a 2 s . c o m*/ final boolean validTarget = MetaUtilities.isValidUriTarget(data); Log.d(TAG, String.format("isStateIdle=%s, validTarget=%s", String.valueOf(isStateIdle), String.valueOf(validTarget))); if (validTarget && isStateIdle) { // File exists and is not being downloaded. if (data.startsWith(ContentResolver.SCHEME_CONTENT)) { Log.d(TAG, "opening file from content uri"); final Intent intent = new Intent(Intent.ACTION_VIEW); final Uri uri = Uri.parse(data); intent.setDataAndType(uri, FileUtilities.getMime(filename)); final Intent chooser = new Intent(Intent.ACTION_VIEW); chooser.putExtra(Intent.EXTRA_INTENT, intent); chooser.putExtra(Intent.EXTRA_TITLE, getText(R.string.dialog_open_with_title)); try { startActivity(intent); } catch (ActivityNotFoundException e) { UIUtil.showToast(this, R.string.toast_no_suitable_activity); } } else { Log.d(TAG, "opening file directly"); File file = null; try { Log.d(TAG, "opening " + data); if (data.startsWith(ContentResolver.SCHEME_FILE)) { file = new File(URI.create(data)); } else { file = new File(data); } } catch (Exception e) { Log.e(TAG, "file uri is empty", e); } if (file != null && file.exists()) { Log.d(TAG, "Resource exists, opening: " + file.getAbsolutePath()); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), FileUtilities.getMime(data)); Intent chooser = new Intent(Intent.ACTION_VIEW); chooser.putExtra(Intent.EXTRA_INTENT, intent); chooser.putExtra(Intent.EXTRA_TITLE, getText(R.string.dialog_open_with_title)); try { startActivity(intent); } catch (ActivityNotFoundException e) { UIUtil.showToast(this, R.string.toast_no_suitable_activity); } } else { Log.d(TAG, "Setting resource as not cached: " + resourcePath); MetaUtilities.setIsCached(resourcePath, false); MetaUtilities.setStateAndData(resourcePath, null, null); UIUtil.showToast(this, R.string.toast_file_not_cached_anymore, false); mResolver.notifyChange(Nodes.CONTENT_URI, null); } } } else if (isFailedDownload) { // File does not exist or download failed. Log.d(TAG, "was: failed download or invalid"); if (NetworkUtil.isConnected(this)) { downloadFile(resourcePath); } else { UIUtil.showToast(this, R.string.toast_no_network); } } else if (isStateIdle && !validTarget) { // File removed from device, need to download. downloadFile(resourcePath); } else if (isDownloading) { UIUtil.showToast(this, "Please wait while downloading..."); } else { Log.e(TAG, "unhandled state: " + resourceState); } }
From source file:com.amaze.carbonfilemanager.activities.MainActivity.java
@Override public void onResume() { super.onResume(); if (materialDialog != null && !materialDialog.isShowing()) { materialDialog.show();//from w w w . j a v a 2 s . c om materialDialog = null; } IntentFilter newFilter = new IntentFilter(); newFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); newFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); newFilter.addDataScheme(ContentResolver.SCHEME_FILE); registerReceiver(mainActivityHelper.mNotificationReceiver, newFilter); registerReceiver(receiver2, new IntentFilter(TAG_INTENT_FILTER_GENERAL)); if (getSupportFragmentManager().findFragmentById(R.id.content_frame).getClass().getName() .contains("TabFragment")) { floatingActionButton.setVisibility(View.VISIBLE); floatingActionButton.showMenuButton(false); } else { floatingActionButton.setVisibility(View.INVISIBLE); floatingActionButton.hideMenuButton(false); } if (SDK_INT >= Build.VERSION_CODES.KITKAT) { // Registering intent filter for OTG IntentFilter otgFilter = new IntentFilter(); otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); otgFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); registerReceiver(mOtgReceiver, otgFilter); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // let's register encryption service to know when we've decrypted Intent encryptIntent = new Intent(this, EncryptService.class); bindService(encryptIntent, mEncryptServiceConnection, 0); if (!isEncryptOpen && encryptBaseFile != null) { // we've opened the file and are ready to delete it // don't move this to ondestroy as we'll be getting destroyed and starting // an async task just before it is not a good idea ArrayList<BaseFile> baseFiles = new ArrayList<>(); baseFiles.add(encryptBaseFile); new DeleteTask(getContentResolver(), this).execute(baseFiles); } } }
From source file:com.android.mail.compose.ComposeActivity.java
/** * Helper function to handle a list of uris to attach. * @return the total size of all successfully attached files. *///w w w. ja va2 s. c o m private long handleAttachmentUrisFromIntent(List<Uri> uris) { ArrayList<Attachment> attachments = Lists.newArrayList(); for (Uri uri : uris) { try { if (uri != null) { if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) { // We must not allow files from /data, even from our process. final File f = new File(uri.getPath()); final String filePath = f.getCanonicalPath(); if (filePath.startsWith(DATA_DIRECTORY_ROOT)) { showErrorToast(getString(R.string.attachment_permission_denied)); Analytics.getInstance().sendEvent(ANALYTICS_CATEGORY_ERRORS, "send_intent_attachment", "data_dir", 0); continue; } } else if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) { // disallow attachments from our own EmailProvider (b/27308057) if (getEmailProviderAuthority().equals(uri.getAuthority())) { showErrorToast(getString(R.string.attachment_permission_denied)); Analytics.getInstance().sendEvent(ANALYTICS_CATEGORY_ERRORS, "send_intent_attachment", "email_provider", 0); continue; } } if (!handleSpecialAttachmentUri(uri)) { final Attachment a = mAttachmentsView.generateLocalAttachment(uri); attachments.add(a); Analytics.getInstance().sendEvent("send_intent_attachment", Utils.normalizeMimeType(a.getContentType()), null, a.size); } } } catch (AttachmentFailureException e) { LogUtils.e(LOG_TAG, e, "Error adding attachment"); showAttachmentTooBigToast(e.getErrorRes()); } catch (IOException | SecurityException e) { LogUtils.e(LOG_TAG, e, "Error adding attachment"); showErrorToast(getString(R.string.attachment_permission_denied)); } } return addAttachments(attachments); }