List of usage examples for android.content ContentResolver getType
public final @Nullable String getType(@NonNull Uri url)
From source file:com.utils.note.rteditor.media.choose.processor.MediaProcessor.java
protected String getMimeType() throws IOException, Exception { if (mOriginalFile.startsWith("content://")) { // ContentProvider file ContentResolver resolver = RTApi.getApplicationContext().getContentResolver(); Uri uri = Uri.parse(mOriginalFile); return resolver.getType(uri); }/*w w w. j av a2 s.co m*/ String extension = RTFileNameUtils.getExtension(mOriginalFile); return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); }
From source file:com.jefftharris.passwdsafe.SyncProviderFragment.java
/** Check whether the sync provider is present */ private boolean checkProvider() { ContentResolver res = getActivity().getContentResolver(); String type = res.getType(PasswdSafeContract.Providers.CONTENT_URI); return (type != null); }
From source file:com.amytech.android.library.views.imagechooser.api.BChooser.java
protected boolean wasVideoSelected(Intent data) { if (data == null) { return false; }/*ww w . j av a2 s .c o m*/ if (data.getType() != null && data.getType().startsWith("video")) { return true; } ContentResolver cR = getContext().getContentResolver(); String type = cR.getType(data.getData()); if (type != null && type.startsWith("video")) { return true; } return false; }
From source file:com.zhihu.matisse.MimeType.java
public boolean checkType(ContentResolver resolver, Uri uri) { MimeTypeMap map = MimeTypeMap.getSingleton(); if (uri == null) { return false; }/*from ww w . jav a 2 s. c o m*/ String type = map.getExtensionFromMimeType(resolver.getType(uri)); String path = null; // lazy load the path and prevent resolve for multiple times boolean pathParsed = false; for (String extension : mExtensions) { if (extension.equals(type)) { return true; } if (!pathParsed) { // we only resolve the path for one time path = PhotoMetadataUtils.getPath(resolver, uri); if (!TextUtils.isEmpty(path)) { path = path.toLowerCase(Locale.US); } pathParsed = true; } if (path != null && path.endsWith(extension)) { return true; } } return false; }
From source file:com.apptentive.android.sdk.model.FileMessage.java
public boolean createStoredFile(Context context, String uriString) { Uri uri = Uri.parse(uriString);//from w w w . ja va2 s. c o m ContentResolver resolver = context.getContentResolver(); String mimeType = resolver.getType(uri); MimeTypeMap mime = MimeTypeMap.getSingleton(); String extension = mime.getExtensionFromMimeType(mimeType); // If we can't get the mime type from the uri, try getting it from the extension. if (extension == null) { extension = MimeTypeMap.getFileExtensionFromUrl(uriString); } if (mimeType == null && extension != null) { mimeType = mime.getMimeTypeFromExtension(extension); } setFileName(uri.getLastPathSegment() + "." + extension); setMimeType(mimeType); InputStream is = null; try { is = new BufferedInputStream(context.getContentResolver().openInputStream(uri)); return createStoredFile(context, is, mimeType); } catch (FileNotFoundException e) { Log.e("File not found while storing file.", e); } catch (IOException e) { Log.a("Error storing image.", e); } finally { Util.ensureClosed(is); } return false; }
From source file:com.Jsu.framework.image.imageChooser.BChooser.java
protected boolean wasVideoSelected(Intent data) { if (data == null) { return false; }// w ww .j a va 2s . com if (data.getType() != null && data.getType().startsWith("video")) { return true; } ContentResolver cR = getContext().getContentResolver(); String type = cR.getType(data.getData()); return type != null && type.startsWith("video"); }
From source file:au.com.cybersearch2.classyfy.MainActivity.java
/** * onCreate//w ww . j a v a 2s .c o m * @see android.support.v7.app.AppCompatActivity#onCreate(android.os.Bundle) */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "In MainActivity onCreate()"); final ClassyFyApplication classyFyApplication = ClassyFyApplication.getInstance(); final MainActivity activity = this; setContentView(R.layout.activity_main); // Complete initialization in background AsyncBackgroundTask starter = new AsyncBackgroundTask(getApplication()) { NodeDetailsBean nodeDetails; @Override public Boolean loadInBackground() { Log.i(TAG, "Loading in background..."); startState = StartState.build; classyFyComponent = classyFyApplication.getClassyFyComponent(); classyFyComponent.inject(activity); // Invoke ClassyFyProvider using ContentResolver to force initialization ContentResolver contentResolver = getContentResolver(); String type = contentResolver.getType(ClassyFySearchEngine.CONTENT_URI); Log.i(TAG, "Search Engine initialized for content type: " + type); Log.i(TAG, "Getting top level record..."); // Get first node, which is root of records tree nodeDetails = getNodeDetailsBean(classyFyApplication, 1); return nodeDetails != null; } @Override public void onLoadComplete(Loader<Boolean> loader, Boolean success) { Log.i(TAG, "Loading completed " + success); startState = success ? StartState.run : StartState.fail; if (success) displayContent(nodeDetails); else displayToast(START_FAIL_MESSAGE); } }; starter.onStartLoading(); }
From source file:com.apptentive.android.sdk.model.FileMessage.java
/** * This method stores an image, and compresses it in the process so it doesn't fill up the disk. Therefore, do not use * it to store an exact copy of the file in question. */// w w w. j av a2 s .c om public boolean internalCreateStoredImage(Context context, String uriString) { Uri uri = Uri.parse(uriString); ContentResolver resolver = context.getContentResolver(); String mimeType = resolver.getType(uri); MimeTypeMap mime = MimeTypeMap.getSingleton(); String extension = mime.getExtensionFromMimeType(mimeType); setFileName(uri.getLastPathSegment() + "." + extension); setMimeType(mimeType); // Create a file to save locally. String localFileName = getStoredFileId(); File localFile = new File(localFileName); // Copy the file contents over. InputStream is = null; CountingOutputStream cos = null; try { is = new BufferedInputStream(context.getContentResolver().openInputStream(uri)); cos = new CountingOutputStream( new BufferedOutputStream(context.openFileOutput(localFile.getPath(), Context.MODE_PRIVATE))); System.gc(); Bitmap smaller = ImageUtil.createScaledBitmapFromStream(is, MAX_STORED_IMAGE_EDGE, MAX_STORED_IMAGE_EDGE, null); // TODO: Is JPEG what we want here? smaller.compress(Bitmap.CompressFormat.JPEG, 95, cos); cos.flush(); Log.d("Bitmap saved, size = " + (cos.getBytesWritten() / 1024) + "k"); smaller.recycle(); System.gc(); } catch (FileNotFoundException e) { Log.e("File not found while storing image.", e); return false; } catch (Exception e) { Log.a("Error storing image.", e); return false; } finally { Util.ensureClosed(is); Util.ensureClosed(cos); } // Create a StoredFile database entry for this locally saved file. StoredFile storedFile = new StoredFile(); storedFile.setId(getStoredFileId()); storedFile.setOriginalUri(uri.toString()); storedFile.setLocalFilePath(localFile.getPath()); storedFile.setMimeType("image/jpeg"); FileStore db = ApptentiveDatabase.getInstance(context); return db.putStoredFile(storedFile); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VideoObj.java
public static DbObject from(Context context, Uri videoUri) throws IOException { // Query gallery for camera picture via // Android ContentResolver interface ContentResolver cr = context.getContentResolver(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 1;//w ww .j a v a 2 s . c o m long videoId = Long.parseLong(videoUri.getLastPathSegment()); Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(cr, videoId, MediaStore.Video.Thumbnails.MINI_KIND, options); int targetSize = 200; int width = curThumb.getWidth(); int height = curThumb.getHeight(); int cropSize = Math.min(width, height); float scaleSize = ((float) targetSize) / cropSize; Matrix matrix = new Matrix(); matrix.postScale(scaleSize, scaleSize); curThumb = Bitmap.createBitmap(curThumb, 0, 0, width, height, matrix, true); JSONObject base = new JSONObject(); String localIp = ContentCorral.getLocalIpAddress(); if (localIp != null) { try { // TODO: Security breach hack? base.put(Contact.ATTR_LAN_IP, localIp); base.put(LOCAL_URI, videoUri.toString()); base.put(MIME_TYPE, cr.getType(videoUri)); } catch (JSONException e) { Log.e(TAG, "impossible json error possible!"); } } ByteArrayOutputStream baos = new ByteArrayOutputStream(); curThumb.compress(Bitmap.CompressFormat.JPEG, 90, baos); byte[] data = baos.toByteArray(); return from(base, data); }
From source file:com.doplgangr.secrecy.FileSystem.Vault.java
public String addFile(final Context context, final Uri uri) { String filename = uri.getLastPathSegment(); try {//from www.java 2 s . c om String realPath = getPath(context, uri); Util.log(realPath, filename); filename = new java.io.File(realPath).getName(); // If we can use real path, better use one. } catch (Exception ignored) { // Leave it. } if (!filename.contains("_thumb") && !filename.contains(".nomedia")) { ContentResolver cR = context.getContentResolver(); MimeTypeMap mime = MimeTypeMap.getSingleton(); String type = mime.getExtensionFromMimeType(cR.getType(uri)); if (type != null) filename = Base64Coder.encodeString(FilenameUtils.removeExtension(filename)) + "." + type; } InputStream is = null; OutputStream out = null; try { InputStream stream = context.getContentResolver().openInputStream(uri); java.io.File addedFile = new java.io.File(path + "/" + filename); addedFile.delete(); addedFile.createNewFile(); is = new BufferedInputStream(stream); byte buffer[] = new byte[Config.bufferSize]; int count; AES_Encryptor enc = new AES_Encryptor(key); out = new CipherOutputStream(new FileOutputStream(addedFile), enc.encryptstream()); while ((count = is.read(buffer)) != -1) out.write(buffer, 0, count); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (is != null) { is.close(); } if (out != null) { out.close(); } } catch (IOException e) { e.printStackTrace(); } } return filename; }