List of usage examples for android.content Intent setClipData
public void setClipData(@Nullable ClipData clip)
From source file:com.home.young.filepicker.AbstractFilePickerActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override/*from ww w . j a v a 2 s .c o m*/ public void onFilesPicked(@NonNull final List<Uri> files) { Intent i = new Intent(); i.putExtra(EXTRA_ALLOW_MULTIPLE, true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = null; for (Uri file : files) { if (clip == null) { clip = new ClipData("Paths", new String[] {}, new ClipData.Item(file)); } else { clip.addItem(new ClipData.Item(file)); } } i.setClipData(clip); } else { ArrayList<String> paths = new ArrayList<>(); for (Uri file : files) { paths.add(file.toString()); } i.putStringArrayListExtra(EXTRA_PATHS, paths); } setResult(Activity.RESULT_OK, i); finish(); }
From source file:cn.tycoon.lighttrans.fileManager.AbstractFilePickerActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override/*from www . j a v a2 s .c o m*/ public void onFilesPicked(final List<Uri> files) { Intent i = new Intent(); i.putExtra(EXTRA_ALLOW_MULTIPLE, true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = null; for (Uri file : files) { if (clip == null) { clip = new ClipData("Paths", new String[] {}, new ClipData.Item(file)); } else { clip.addItem(new ClipData.Item(file)); } } i.setClipData(clip); } else { ArrayList<String> paths = new ArrayList<>(); for (Uri file : files) { paths.add(file.toString()); } i.putStringArrayListExtra(EXTRA_PATHS, paths); } setResult(Activity.RESULT_OK, i); finish(); }
From source file:com.commonsware.android.camcon.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState == null) { output = new File(new File(getFilesDir(), PHOTOS), FILENAME); if (output.exists()) { output.delete();/*from w ww . j av a 2 s . c om*/ } else { output.getParentFile().mkdirs(); } Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri outputUri = FileProvider.getUriForFile(this, AUTHORITY, output); i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri); i.setClipData(clip); i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else { List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } } try { startActivityForResult(i, CONTENT_REQUEST); } catch (ActivityNotFoundException e) { Toast.makeText(this, R.string.msg_no_camera, Toast.LENGTH_LONG).show(); finish(); } } else { output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME); } }
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 www . ja va2s. c o m }
From source file:com.waz.zclient.controllers.notifications.NotificationsController.java
private PendingIntent getGalleryIntent(Uri uri) { // TODO: AN-2276 - Replace with ShareCompat.IntentBuilder Intent galleryIntent = new Intent(Intent.ACTION_VIEW); galleryIntent.setDataAndTypeAndNormalize(uri, "image/*"); galleryIntent.setClipData(new ClipData(null, new String[] { "image/*" }, new ClipData.Item(uri))); galleryIntent.putExtra(Intent.EXTRA_STREAM, uri); return PendingIntent.getActivity(context, 0, galleryIntent, 0); }
From source file:com.android.gallery3d.gadget.WidgetConfigure.java
private void setChoosenPhoto(final Intent data) { AsyncTask.execute(new Runnable() { @Override/*from w ww. j av a 2 s. co m*/ public void run() { Resources res = getResources(); float width = res.getDimension(R.dimen.appwidget_width); float height = res.getDimension(R.dimen.appwidget_height); // We try to crop a larger image (by scale factor), but there is still // a bound on the binder limit. float scale = Math.min(WIDGET_SCALE_FACTOR, MAX_WIDGET_SIDE / Math.max(width, height)); int widgetWidth = Math.round(width * scale); int widgetHeight = Math.round(height * scale); File cropSrc = new File(getCacheDir(), "crop_source.png"); File cropDst = new File(getCacheDir(), "crop_dest.png"); mPickedItem = data.getData(); if (!copyUriToFile(mPickedItem, cropSrc)) { setResult(Activity.RESULT_CANCELED); finish(); return; } mCropSrc = FileProvider.getUriForFile(WidgetConfigure.this, "com.android.gallery3d.fileprovider", new File(cropSrc.getAbsolutePath())); mCropDst = FileProvider.getUriForFile(WidgetConfigure.this, "com.android.gallery3d.fileprovider", new File(cropDst.getAbsolutePath())); Intent request = new Intent(CropActivity.CROP_ACTION).putExtra(CropExtras.KEY_OUTPUT_X, widgetWidth) .putExtra(CropExtras.KEY_OUTPUT_Y, widgetHeight) .putExtra(CropExtras.KEY_ASPECT_X, widgetWidth) .putExtra(CropExtras.KEY_ASPECT_Y, widgetHeight) .putExtra(CropExtras.KEY_SCALE_UP_IF_NEEDED, true).putExtra(CropExtras.KEY_SCALE, true) .putExtra(CropExtras.KEY_RETURN_DATA, false).setDataAndType(mCropSrc, "image/*") .addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); request.putExtra(MediaStore.EXTRA_OUTPUT, mCropDst); request.setClipData(ClipData.newRawUri(MediaStore.EXTRA_OUTPUT, mCropDst)); startActivityForResult(request, REQUEST_CROP_IMAGE); } }); }
From source file:com.commonsware.android.camcon.CameraContentDemoActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (savedInstanceState == null) { output = new File(new File(getFilesDir(), PHOTOS), FILENAME); if (output.exists()) { output.delete();/*from w w w .j a v a 2 s .c o m*/ } else { output.getParentFile().mkdirs(); } } else { output = (File) savedInstanceState.getSerializable(EXTRA_FILENAME); } outputUri = FileProvider.getUriForFile(this, AUTHORITY, output); if (savedInstanceState == null) { i.putExtra(MediaStore.EXTRA_OUTPUT, outputUri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = ClipData.newUri(getContentResolver(), "A photo", outputUri); i.setClipData(clip); i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else { List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, outputUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } } startActivityForResult(i, CONTENT_REQUEST); } }
From source file:org.cm.podd.report.activity.SettingActivity.java
private void captureImageFromCamera() { mCurrentPhotoUri = getImageUri();//ww w . j ava2 s .c o m Intent photoTakerIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); photoTakerIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 1024 * 1024); photoTakerIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); photoTakerIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoUri); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) { photoTakerIntent .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { photoTakerIntent.setClipData(ClipData.newRawUri("", mCurrentPhotoUri)); } } startActivityForResult(photoTakerIntent, REQ_CODE_TAKE_IMAGE); }
From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java
private void onFinished(Uri... uris) { Log.d(TAG, "onFinished() " + Arrays.toString(uris)); final Intent intent = new Intent(); if (uris.length == 1) { intent.setData(uris[0]);/* w ww. j ava2 s . co m*/ } else if (uris.length > 1) { final ClipData clipData = new ClipData(null, mState.acceptMimes, new ClipData.Item(uris[0])); for (int i = 1; i < uris.length; i++) { clipData.addItem(new ClipData.Item(uris[i])); } intent.setClipData(clipData); } if (mState.action == ACTION_GET_CONTENT) { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); } setResult(Activity.RESULT_OK, intent); finish(); }
From source file:dev.dworks.apps.anexplorer.DocumentsActivity.java
private void onFinished(Uri... uris) { Log.d(TAG, "onFinished() " + Arrays.toString(uris)); final Intent intent = new Intent(); if (uris.length == 1) { intent.setData(uris[0]);//w w w. ja v a 2 s . co m } else if (uris.length > 1) { final ClipData clipData = new ClipData(null, mState.acceptMimes, new ClipData.Item(uris[0])); for (int i = 1; i < uris.length; i++) { clipData.addItem(new ClipData.Item(uris[i])); } if (Utils.hasJellyBean()) { intent.setClipData(clipData); } else { intent.setData(uris[0]); } } if (mState.action == ACTION_GET_CONTENT || mState.action == ACTION_BROWSE) { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } setResult(Activity.RESULT_OK, intent); finish(); }