List of usage examples for android.content ClipDescription compareMimeTypes
public static boolean compareMimeTypes(String concreteType, String desiredType)
From source file:com.example.android.commitcontent.app.ImageKeyboard.java
private boolean isCommitContentSupported(@Nullable EditorInfo editorInfo, @NonNull String mimeType) { if (editorInfo == null) { return false; }/*w w w . j av a 2 s. c om*/ final InputConnection ic = getCurrentInputConnection(); if (ic == null) { return false; } if (!validatePackageName(editorInfo)) { return false; } final String[] supportedMimeTypes = EditorInfoCompat.getContentMimeTypes(editorInfo); for (String supportedMimeType : supportedMimeTypes) { if (ClipDescription.compareMimeTypes(mimeType, supportedMimeType)) { return true; } } return false; }
From source file:org.sufficientlysecure.keychain.ui.DecryptListFragment.java
private void processResult(final Uri uri) { new AsyncTask<Void, Void, Void>() { @Override/*w ww .ja v a 2 s . c o m*/ protected Void doInBackground(Void... params) { InputDataResult result = mInputDataResults.get(uri); Context context = getActivity(); if (context == null) { return null; } for (int i = 0; i < result.getOutputUris().size(); i++) { Uri outputUri = result.getOutputUris().get(i); if (mIconCache.containsKey(outputUri)) { continue; } OpenPgpMetadata metadata = result.mMetadata.get(i); String type = metadata.getMimeType(); Drawable icon = null; if (ClipDescription.compareMimeTypes(type, "text/plain")) { // noinspection deprecation, this should be called from Context, but not available in minSdk icon = getResources().getDrawable(R.drawable.ic_chat_black_24dp); } else if (ClipDescription.compareMimeTypes(type, "application/octet-stream")) { // icons for this are just confusing // noinspection deprecation, this should be called from Context, but not available in minSdk icon = getResources().getDrawable(R.drawable.ic_doc_generic_am); } else if (ClipDescription.compareMimeTypes(type, Constants.MIME_TYPE_KEYS)) { // noinspection deprecation, this should be called from Context, but not available in minSdk icon = getResources().getDrawable(R.drawable.ic_key_plus_grey600_24dp); } else if (ClipDescription.compareMimeTypes(type, "image/*")) { int px = FormattingUtils.dpToPx(context, 32); Bitmap bitmap = FileHelper.getThumbnail(context, outputUri, new Point(px, px)); icon = new BitmapDrawable(context.getResources(), bitmap); } if (icon == null) { final Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(outputUri, type); final List<ResolveInfo> matches = context.getPackageManager().queryIntentActivities(intent, 0); // noinspection LoopStatementThatDoesntLoop for (ResolveInfo match : matches) { icon = match.loadIcon(getActivity().getPackageManager()); break; } } if (icon != null) { mIconCache.put(outputUri, icon); } } return null; } @Override protected void onPostExecute(Void v) { InputDataResult result = mInputDataResults.get(uri); mAdapter.addResult(uri, result); } }.execute(); }
From source file:net.sf.xfd.provider.PublicProvider.java
@Nullable @Override/*from ww w. j a v a 2 s. c o m*/ public AssetFileDescriptor openTypedAssetFile(@NonNull Uri uri, @NonNull String mimeTypeFilter, @Nullable Bundle opts, @Nullable CancellationSignal signal) throws FileNotFoundException { if ("*/*".equals(mimeTypeFilter)) { // If they can take anything, the untyped open call is good enough. return openAssetFile(uri, "r", signal); } String[] possibleTypes = getStreamTypes(uri, mimeTypeFilter); if (possibleTypes != null) { for (String possibleType : possibleTypes) { if (ClipDescription.compareMimeTypes(possibleType, mimeTypeFilter)) { // Use old untyped open call if this provider has a type for this // URI and it matches the request. return openAssetFile(uri, "r", signal); } } } throw new FileNotFoundException("Can't open " + uri + " as type " + mimeTypeFilter); }
From source file:org.sufficientlysecure.keychain.ui.DecryptListFragment.java
public void displayWithViewIntent(InputDataResult result, int index, boolean share, boolean forceChooser) { Activity activity = getActivity();/* w w w.java 2 s. co m*/ if (activity == null) { return; } Uri outputUri = result.getOutputUris().get(index); OpenPgpMetadata metadata = result.mMetadata.get(index); // text/plain is a special case where we extract the uri content into // the EXTRA_TEXT extra ourselves, and display a chooser which includes // OpenKeychain's internal viewer if ("text/plain".equals(metadata.getMimeType())) { if (share) { try { String plaintext = FileHelper.readTextFromUri(activity, outputUri, null); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, plaintext); Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_share)); startActivity(chooserIntent); } catch (IOException e) { Notify.create(activity, R.string.error_preparing_data, Style.ERROR).show(); } return; } Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(outputUri, "text/plain"); if (forceChooser) { LabeledIntent internalIntent = new LabeledIntent( new Intent(intent).setClass(activity, DisplayTextActivity.class) .putExtra(DisplayTextActivity.EXTRA_RESULT, result.mDecryptVerifyResult) .putExtra(DisplayTextActivity.EXTRA_METADATA, metadata), BuildConfig.APPLICATION_ID, R.string.view_internal, R.mipmap.ic_launcher); Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_show)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[] { internalIntent }); startActivity(chooserIntent); } else { intent.setClass(activity, DisplayTextActivity.class); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra(DisplayTextActivity.EXTRA_RESULT, result.mDecryptVerifyResult); intent.putExtra(DisplayTextActivity.EXTRA_METADATA, metadata); startActivity(intent); } } else { Intent intent; if (share) { intent = new Intent(Intent.ACTION_SEND); intent.setType(metadata.getMimeType()); intent.putExtra(Intent.EXTRA_STREAM, outputUri); } else { intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(outputUri, metadata.getMimeType()); if (!forceChooser && Constants.MIME_TYPE_KEYS.equals(metadata.getMimeType())) { // bind Intent to this OpenKeychain, don't allow other apps to intercept here! intent.setPackage(getActivity().getPackageName()); } } intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_show)); chooserIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); if (!share && ClipDescription.compareMimeTypes(metadata.getMimeType(), "text/*")) { LabeledIntent internalIntent = new LabeledIntent( new Intent(intent).setClass(activity, DisplayTextActivity.class) .putExtra(DisplayTextActivity.EXTRA_RESULT, result.mDecryptVerifyResult) .putExtra(DisplayTextActivity.EXTRA_METADATA, metadata), BuildConfig.APPLICATION_ID, R.string.view_internal, R.mipmap.ic_launcher); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[] { internalIntent }); } startActivity(chooserIntent); } }