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:cn.edu.wyu.documentviewer.RecentsProvider.java
public static Uri buildRecent() { return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY).appendPath("recent") .build();//from w ww . java 2 s. com }
From source file:com.android.dialer.lookup.yellowpages.YellowPagesReverseLookup.java
/** * Lookup image/* w w w .ja v a 2 s.c om*/ * * @param context The application context * @param uri The image URI */ public Bitmap lookupImage(Context context, Uri uri) { if (uri == null) { throw new NullPointerException("URI is null"); } Log.e(TAG, "Fetching " + uri); String scheme = uri.getScheme(); if (scheme.startsWith("http")) { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(uri.toString()); try { HttpResponse response = client.execute(request); int responseCode = response.getStatusLine().getStatusCode(); ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); byte[] responseBytes = out.toByteArray(); if (responseCode == HttpStatus.SC_OK) { Bitmap bmp = BitmapFactory.decodeByteArray(responseBytes, 0, responseBytes.length); return bmp; } } catch (IOException e) { Log.e(TAG, "Failed to retrieve image", e); } } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) { try { ContentResolver cr = context.getContentResolver(); Bitmap bmp = BitmapFactory.decodeStream(cr.openInputStream(uri)); return bmp; } catch (FileNotFoundException e) { Log.e(TAG, "Failed to retrieve image", e); } } return null; }
From source file:cn.edu.wyu.documentviewer.RecentsProvider.java
public static Uri buildState(String authority, String rootId, String documentId) { return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY).appendPath("state") .appendPath(authority).appendPath(rootId).appendPath(documentId).build(); }
From source file:syncthing.android.service.ServiceSettings.java
@Inject public ServiceSettings(@ForApplication Context appContext, ConnectivityManager cm, WifiManager wm, @Named("settingsAuthority") String authority, ReceiverHelper receiverHelper) { this.appContext = appContext; this.cm = cm; this.wm = wm; this.callUri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(authority).build(); this.receiverHelper = receiverHelper; }
From source file:cn.edu.wyu.documentviewer.RecentsProvider.java
public static Uri buildResume(String packageName) { return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(AUTHORITY).appendPath("resume") .appendPath(packageName).build(); }
From source file:de.kodejak.hashr.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); mTitle = getTitle();/* w w w.j ava 2 s .c o m*/ // Set a toolbar which will replace the action bar. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Set up the drawer. mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), toolbar); Intent intent = getIntent(); String action = intent.getAction(); if (action.compareTo(Intent.ACTION_VIEW) == 0) { String scheme = intent.getScheme(); ContentResolver resolver = getContentResolver(); if (scheme.compareTo(ContentResolver.SCHEME_CONTENT) == 0) { Uri uri = intent.getData(); String name = getContentName(resolver, uri); Log.v("tag", "Content intent detected: " + action + " : " + intent.getDataString() + " : " + intent.getType() + " : " + name); //What TODO? } else if (scheme.compareTo(ContentResolver.SCHEME_FILE) == 0) { lastSumFile = intent.getData().getPath(); forcedFragmentNum = prepareOpenSumFile(lastSumFile); if (forcedFragmentNum > -1) { mNavigationDrawerFragment.selectItem(forcedFragmentNum); } } } }
From source file:com.cooliris.media.UriTexture.java
public static final Bitmap createFromUri(Context context, String uri, int maxResolutionX, int maxResolutionY, long cacheId, ClientConnectionManager connectionManager) throws IOException, URISyntaxException, OutOfMemoryError { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false;/*w ww . j a v a 2s .co m*/ options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = true; long crc64 = 0; Bitmap bitmap = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT)) { // We need the filepath for the given content uri crc64 = cacheId; } else { crc64 = Utils.Crc64Long(uri); } bitmap = createFromCache(crc64, maxResolutionX); if (bitmap != null) { return bitmap; } final boolean local = uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith("file://"); // Get the input stream for computing the sample size. BufferedInputStream bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Compute the sample size, i.e., not decoding real pixels. if (bufferedInput != null) { options.inSampleSize = computeSampleSize(bufferedInput, maxResolutionX, maxResolutionY); } else { return null; } // Get the input stream again for decoding it to a bitmap. bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Decode bufferedInput to a bitmap. if (bufferedInput != null) { options.inDither = false; options.inJustDecodeBounds = false; options.inPurgeable = true; Thread timeoutThread = new Thread("BitmapTimeoutThread") { public void run() { try { Thread.sleep(6000); options.requestCancelDecode(); } catch (InterruptedException e) { } } }; timeoutThread.start(); bitmap = BitmapFactory.decodeStream(bufferedInput, null, options); } if (bitmap != null) { bitmap = Utils.resizeBitmap(bitmap, maxResolutionX); } if ((options.inSampleSize > 1 || !local) && bitmap != null) { writeToCache(crc64, bitmap, maxResolutionX); } return bitmap; }
From source file:com.xlauncher.media.UriTexture.java
public static final Bitmap createFromUri(Context context, String uri, int maxResolutionX, int maxResolutionY, long cacheId, ClientConnectionManager connectionManager) throws IOException, URISyntaxException, OutOfMemoryError { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false;/*from w ww. j av a 2 s . c o m*/ options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = true; long crc64 = 0; Bitmap bitmap = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT)) { // We need the filepath for the given content uri crc64 = cacheId; } else { crc64 = Utils.Crc64Long(uri); } bitmap = createFromCache(crc64, maxResolutionX); if (bitmap != null) { return bitmap; } final boolean local = uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith("file://"); // Get the input stream for computing the sample size. BufferedInputStream bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Compute the sample size, i.e., not decoding real pixels. if (bufferedInput != null) { options.inSampleSize = computeSampleSize(bufferedInput, maxResolutionX, maxResolutionY); } else { return null; } // Get the input stream again for decoding it to a bitmap. bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Decode bufferedInput to a bitmap. if (bufferedInput != null) { options.inDither = false; options.inJustDecodeBounds = false; options.inPurgeable = true; Thread timeoutThread = new Thread("BitmapTimeoutThread") { public void run() { try { Thread.sleep(6000); options.requestCancelDecode(); } catch (InterruptedException e) { } } }; timeoutThread.start(); bitmap = BitmapFactory.decodeStream(bufferedInput, null, options); } if (bitmap != null) { bitmap = Utils.resizeBitmap(context, bitmap, maxResolutionX, false); } if ((options.inSampleSize > 1 || !local) && bitmap != null) { writeToCache(crc64, bitmap, maxResolutionX); } return bitmap; }
From source file:com.timtory.wmgallery.media.UriTexture.java
public static final Bitmap createFromUri(Context context, String uri, int maxResolutionX, int maxResolutionY, long cacheId, ClientConnectionManager connectionManager) throws IOException, URISyntaxException, OutOfMemoryError { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false;//from www . ja va 2 s.co m options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = true; long crc64 = 0; Bitmap bitmap = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT)) { // We need the filepath for the given content uri crc64 = cacheId; } else { crc64 = Utils.Crc64Long(uri); } bitmap = createFromCache(crc64, maxResolutionX); if (bitmap != null) { return bitmap; } final boolean local = uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith("file://"); // Get the input stream for computing the sample size. BufferedInputStream bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Compute the sample size, i.e., not decoding real pixels. if (bufferedInput != null) { options.inSampleSize = computeSampleSize(bufferedInput, maxResolutionX, maxResolutionY); } else { return null; } // Get the input stream again for decoding it to a bitmap. bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Decode bufferedInput to a bitmap. if (bufferedInput != null) { options.inDither = false; options.inJustDecodeBounds = false; options.inPurgeable = true; Thread timeoutThread = new Thread("BitmapTimeoutThread") { public void run() { try { Thread.sleep(6000); options.requestCancelDecode(); } catch (InterruptedException e) { } } }; timeoutThread.start(); bitmap = BitmapFactory.decodeStream(bufferedInput, null, options); } if (bitmap != null) { bitmap = Utils.resizeBitmap(context, bitmap, maxResolutionX); } if ((options.inSampleSize > 1 || !local) && bitmap != null) { writeToCache(crc64, bitmap, maxResolutionX); } return bitmap; }
From source file:com.android.gallery3d.data.UriImage.java
private int openOrDownloadInner(JobContext jc) { String scheme = mUri.getScheme(); if (ContentResolver.SCHEME_CONTENT.equals(scheme) || ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme) || ContentResolver.SCHEME_FILE.equals(scheme)) { try {//from ww w .ja v a 2s . c o m if (MIME_TYPE_JPEG.equalsIgnoreCase(mContentType)) { InputStream is = mApplication.getContentResolver().openInputStream(mUri); mRotation = Exif.getOrientation(is); Utils.closeSilently(is); } mFileDescriptor = mApplication.getContentResolver().openFileDescriptor(mUri, "r"); if (jc.isCancelled()) return STATE_INIT; return STATE_DOWNLOADED; } catch (FileNotFoundException e) { Log.w(TAG, "fail to open: " + mUri, e); return STATE_ERROR; } } else { try { URL url = new URI(mUri.toString()).toURL(); mCacheEntry = mApplication.getDownloadCache().download(jc, url); if (jc.isCancelled()) return STATE_INIT; if (mCacheEntry == null) { Log.w(TAG, "download failed " + url); return STATE_ERROR; } if (MIME_TYPE_JPEG.equalsIgnoreCase(mContentType)) { InputStream is = new FileInputStream(mCacheEntry.cacheFile); mRotation = Exif.getOrientation(is); Utils.closeSilently(is); } mFileDescriptor = ParcelFileDescriptor.open(mCacheEntry.cacheFile, ParcelFileDescriptor.MODE_READ_ONLY); return STATE_DOWNLOADED; } catch (Throwable t) { Log.w(TAG, "download error", t); return STATE_ERROR; } } }