List of usage examples for android.content ContentResolver SCHEME_CONTENT
String SCHEME_CONTENT
To view the source code for android.content ContentResolver SCHEME_CONTENT.
Click Source Link
From source file:com.tandong.sa.sherlock.widget.SuggestionsAdapter.java
public Cursor getSuggestions(String query, int limit) { if (mSearchable == null) { return null; }//from w ww. j a v a 2s. c om String authority = mSearchable.getSuggestAuthority(); if (authority == null) { return null; } Uri.Builder uriBuilder = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(authority) .query("") // TODO: Remove, workaround for a bug in // Uri.writeToParcel() .fragment(""); // TODO: Remove, workaround for a bug in // Uri.writeToParcel() // if content path provided, insert it now final String contentPath = mSearchable.getSuggestPath(); if (contentPath != null) { uriBuilder.appendEncodedPath(contentPath); } // append standard suggestion query path uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY); // get the query selection, may be null String selection = mSearchable.getSuggestSelection(); // inject query, either as selection args or inline String[] selArgs = null; if (selection != null) { // use selection if provided selArgs = new String[] { query }; } else { // no selection, use REST pattern uriBuilder.appendPath(query); } if (limit > 0) { uriBuilder.appendQueryParameter("limit", String.valueOf(limit)); } Uri uri = uriBuilder.build(); // finally, make the query return mContext.getContentResolver().query(uri, null, selection, selArgs, null); }
From source file:com.android.emailcommon.utility.AttachmentUtilities.java
/** * @return mime-type for a {@link Uri}.//from w w w .j av a 2s . c om * - 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.commonsware.android.diceware.PassphraseFragment.java
private static DocumentFileCompat buildDocFileForUri(Context ctxt, Uri document) { DocumentFileCompat docFile;/*from w w w. j a v a 2 s .c o m*/ if (document.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { docFile = DocumentFileCompat.fromSingleUri(ctxt, document); } else { docFile = DocumentFileCompat.fromFile(new File(document.getPath())); } return (docFile); }
From source file:uk.co.senab.photup.model.PhotoUpload.java
public Bitmap getThumbnailImage(Context context) { if (ContentResolver.SCHEME_CONTENT.equals(getOriginalPhotoUri().getScheme())) { return getThumbnailImageFromMediaStore(context); }// w ww. j av a2 s.c o m final Resources res = context.getResources(); int size = res.getBoolean(R.bool.load_mini_thumbnails) ? MINI_THUMBNAIL_SIZE : MICRO_THUMBNAIL_SIZE; if (size == MINI_THUMBNAIL_SIZE && res.getBoolean(R.bool.sample_mini_thumbnails)) { size /= 2; } try { Bitmap bitmap = Utils.decodeImage(context.getContentResolver(), getOriginalPhotoUri(), size); bitmap = Utils.rotate(bitmap, getExifRotation(context)); return bitmap; } catch (FileNotFoundException e) { e.printStackTrace(); return null; } }
From source file:com.afwsamples.testdpc.SetupManagementFragment.java
private void specifyLogoUri(Intent intent) { intent.putExtra(EXTRA_PROVISIONING_LOGO_URI, mLogoUri); if (mLogoUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setClipData(ClipData.newUri(getActivity().getContentResolver(), "", mLogoUri)); }/*from ww w.ja v a 2s . com*/ }
From source file:org.transdroid.gui.TorrentsFragment.java
public void handleIntent(final Intent startIntent) { // Handle new intents that come from either a regular application startup, a startup from a // new intent or a new intent being send with the application already started if (startIntent != null && (startIntent.getData() != null || (startIntent.getAction() != null && startIntent.getAction().equals(Transdroid.INTENT_ADD_MULTIPLE))) && !isLaunchedFromHistory(startIntent)) { if (startIntent.getAction() != null && startIntent.getAction().equals(Transdroid.INTENT_ADD_MULTIPLE)) { // Intent should have some extras pointing to possibly multiple torrents String[] urls = startIntent.getStringArrayExtra(Transdroid.INTENT_TORRENT_URLS); String[] titles = startIntent.getStringArrayExtra(Transdroid.INTENT_TORRENT_TITLES); if (urls != null) { for (int i = 0; i < urls.length; i++) { addTorrentByUrl(urls[i], (titles != null && titles.length >= i ? titles[i] : "Torrent")); }/*w w w . j a v a 2 s.co m*/ } } else { // Intent should have some Uri data pointing to a single torrent String data = startIntent.getDataString(); if (data != null && startIntent.getData() != null && startIntent.getData().getScheme() != null) { // From Android 4.2 the file path is not directly in the Intent :( but rather in the 'Download manager' cursor if (startIntent.getData().getScheme().equals(ContentResolver.SCHEME_CONTENT)) { addTorrentFromDownloads(startIntent.getData()); } else if (startIntent.getData().getScheme().equals(HttpHelper.SCHEME_HTTP) || startIntent.getData().getScheme().equals(HttpHelper.SCHEME_HTTPS)) { // From a global intent to add a .torrent file via URL (maybe form the browser) String title = data.substring(data.lastIndexOf("/")); if (startIntent.hasExtra(Transdroid.INTENT_TORRENT_TITLE)) { title = startIntent.getStringExtra(Transdroid.INTENT_TORRENT_TITLE); } addTorrentByUrl(data, title); } else if (startIntent.getData().getScheme().equals(HttpHelper.SCHEME_MAGNET)) { // From a global intent to add a magnet link via URL (usually from the browser) addTorrentByMagnetUrl(data); } else if (startIntent.getData().getScheme().equals(HttpHelper.SCHEME_FILE)) { // From a global intent to add via the contents of a local .torrent file (maybe form a file manager) addTorrentByFile(data); } } } } // Possibly switch to a specific daemon (other than the last used) boolean forceUpdate = false; if (startIntent != null && !isLaunchedFromHistory(startIntent) && startIntent.hasExtra(Transdroid.INTENT_OPENDAEMON)) { String openDaemon = startIntent.getStringExtra(Transdroid.INTENT_OPENDAEMON); if (!daemon.getSettings().getIdString().equals(openDaemon)) { int openDaemonI = (openDaemon == null || openDaemon.equals("") ? 0 : Integer.parseInt(openDaemon)); if (openDaemonI >= allDaemonSettings.size()) { openDaemonI = 0; } forceUpdate = true; switchDaemonConfig(openDaemonI); } } if (forceUpdate || allTorrents == null) { // Not swithcing to another daemon and no known list of torrents: update updateTorrentList(); } else { // We retained the list of torrents form the fragment state: show again updateStatusText(null); updateTorrentsView(false); } }
From source file:com.aboveware.sms.contacts.ContactSuggestionsAdapter.java
/** * Import of hidden method: SearchManager.getSuggestions(SearchableInfo, String, int). *///from w ww. j a v a 2s . c o m Cursor getSearchManagerSuggestions(SearchableInfo searchable, String query, int limit) { if (searchable == null) { return null; } String authority = searchable.getSuggestAuthority(); if (authority == null) { return null; } Uri.Builder uriBuilder = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(authority) .query("") // TODO: // Remove, // workaround // for a bug // in // Uri.writeToParcel() .fragment(""); // TODO: Remove, workaround for a bug in Uri.writeToParcel() // if content path provided, insert it now final String contentPath = searchable.getSuggestPath(); if (contentPath != null) { uriBuilder.appendEncodedPath(contentPath); } // append standard suggestion query path uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY); // get the query selection, may be null String selection = searchable.getSuggestSelection(); // inject query, either as selection args or inline String[] selArgs = null; if (selection != null) { // use selection if provided selArgs = new String[] { query }; } else { // no selection, use REST pattern uriBuilder.appendPath(query); } if (limit > 0) { uriBuilder.appendQueryParameter("limit", String.valueOf(limit)); } Uri uri = uriBuilder.build(); // finally, make the query return mContext.getContentResolver().query(uri, null, selection, selArgs, null); }
From source file:android.webkit.cts.WebViewTest.java
@UiThreadTest public void testLoadUrlDoesNotStripParamsWhenLoadingContentUrls() throws Exception { if (!NullWebViewUtils.isWebViewAvailable()) { return;// w w w .j a v a 2 s .c om } Uri.Builder uriBuilder = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority(MockContentProvider.AUTHORITY); uriBuilder.appendPath("foo.html").appendQueryParameter("param", "bar"); String url = uriBuilder.build().toString(); mOnUiThread.loadUrlAndWaitForCompletion(url); // verify the parameter is not stripped. Uri uri = Uri.parse(mWebView.getTitle()); assertEquals("bar", uri.getQueryParameter("param")); }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static boolean isValidUriTarget(String data) { if (data == null) { Log.d(TAG, "uri is null"); return false; } else if (data.startsWith(ContentResolver.SCHEME_CONTENT)) { Log.d(TAG, "checking content uri"); return isValidUri(Uri.parse(data)); } else if (data.startsWith(ContentResolver.SCHEME_FILE)) { try {//from w ww . j ava2 s . c om Log.d(TAG, "checking file uri"); return new File(URI.create(data)).exists(); } catch (IllegalArgumentException e) { // We have received wrong uri. Failed upload shall be cleaned up. return false; } } else if (new File(data).exists()) { return true; } else { Log.e(TAG, "unknown uri: " + data); } return false; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
/** * For a given file {@link Uri} string, we check if its hash has a * corresponding entry in the {@link MetaProvider}, telling thus whether the * file from under given {@link Uri} string has been already uploaded. * //from www .j a v a 2 s . c o m * @param uriString * the uri string which content we are checking * @return resourcePath if content under uri has been already uploaded, * null otherwise */ public static String isUploaded(String uriString) { File file = null; String fileHash = null; if (uriString.startsWith(ContentResolver.SCHEME_CONTENT)) { final String[] projection = new String[] { MediaColumns.DATA }; final Cursor c = sResolver.query(Uri.parse(uriString), projection, null, null, null); try { if (c.moveToFirst()) { String data = c.getString(c.getColumnIndex(MediaColumns.DATA)); file = new File(data); } else { return null; } } finally { c.close(); } } else if (uriString.startsWith(ContentResolver.SCHEME_FILE)) { final URI fileURI = URI.create(Uri.encode(uriString, ":/")); file = new File(fileURI); } else { Log.e(TAG, "Tried to check malformed uri string: " + uriString); return null; } try { if (file != null && file.exists()) { fileHash = HashUtils.getSha1(file); Log.d(TAG, String.format("Computed hash: '%s'", fileHash)); } else { throw new FileNotFoundException("isUploaded()"); } } catch (Exception e) { Log.e(TAG, "Can't compute file hash!", e); return null; } final String[] projection = new String[] { Nodes.NODE_RESOURCE_PATH }; final String selection = Nodes.NODE_HASH + "=?"; final String[] selectionArgs = new String[] { fileHash }; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); String resourcePath = null; try { if (c.moveToFirst()) { resourcePath = c.getString(c.getColumnIndex(Nodes.NODE_RESOURCE_PATH)); Log.d(TAG, "Corresponding file hash found: " + resourcePath); } else { Log.d(TAG, "Corresponding file hash not found."); } } finally { c.close(); } return resourcePath; }