Java Code Examples for android.content.ClipData#newUri()
The following examples show how to use
android.content.ClipData#newUri() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CopyToClipboardTask.java From edslite with GNU General Public License v2.0 | 6 votes |
public static ClipData makeClipData(Context context, Location location, Iterable<Path> paths) { Iterator<Path> pi = paths.iterator(); if(!pi.hasNext()) return null; Path path = pi.next(); ContentResolver cr = context.getContentResolver(); ClipData clip = ClipData.newUri( cr, path.getPathString(), MainContentProvider.getContentUriFromLocation(location, path) ); while(pi.hasNext()) { path = pi.next(); clip.addItem( new ClipData.Item( MainContentProvider.getContentUriFromLocation( location, path ) ) ); } return clip; }
Example 2
Source File: AboutDialogBase.java From edslite with GNU General Public License v2.0 | 6 votes |
private void sendLogFile(Location logLocation) { Context ctx = getActivity(); Uri uri = MainContentProvider.getContentUriFromLocation(logLocation); Intent actionIntent = new Intent(Intent.ACTION_SEND); actionIntent.setType("text/plain"); actionIntent.putExtra(Intent.EXTRA_STREAM, uri); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData cp = ClipData.newUri( ctx.getContentResolver(), ctx.getString(R.string.get_program_log), uri ); actionIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); actionIntent.setClipData(cp); } Intent startIntent = Intent.createChooser( actionIntent, ctx.getString(R.string.save_log_file_to) ); startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(startIntent); }
Example 3
Source File: ClipboardUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 复制 URI 到剪贴板 * @param uri {@link Uri} * @return {@code true} success, {@code false} fail */ public static boolean copyUri(final Uri uri) { try { ClipboardManager clipManager = AppUtils.getClipboardManager(); // 复制的数据 ClipData clipData = ClipData.newUri(ResourceUtils.getContentResolver(), "", uri); // 设置复制的数据 clipManager.setPrimaryClip(clipData); return true; } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "copyUri"); } return false; }
Example 4
Source File: BrowserServiceFileProvider.java From custom-tabs-client with Apache License 2.0 | 5 votes |
/** * Grant the read permission to a list of {@link Uri} sent through a {@link Intent}. * @param intent The sending Intent which holds a list of Uri. * @param uris A list of Uri generated by generateUri(Context, Bitmap, String, int, * List<String>). * @param context The context requests to grant the permission. */ public static void grantReadPermission(Intent intent, List<Uri> uris, Context context) { if (uris == null || uris.size() == 0) return; ContentResolver resolver = context.getContentResolver(); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); ClipData clipData = ClipData.newUri(resolver, CLIP_DATA_LABEL, uris.get(0)); for (int i = 1; i < uris.size(); i++) { clipData.addItem(new ClipData.Item(uris.get(i))); } intent.setClipData(clipData); }
Example 5
Source File: LinksHelper.java From redgram-for-reddit with GNU General Public License v3.0 | 5 votes |
public static MaterialDialog.ListCallback getCopyCallback(Context context, ToastHandler toastHandler, PostItem item) { return (materialDialog, view, i, charSequence) -> { Uri urlToOpen = getUriToOpen(item, charSequence); if (urlToOpen != null) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newUri(context.getContentResolver(), "URI", urlToOpen); clipboard.setPrimaryClip(clip); toastHandler.showToast("Link Copied", Toast.LENGTH_SHORT); } }; }
Example 6
Source File: ClipboardHelper.java From ProjectX with Apache License 2.0 | 5 votes |
/** * 复制 * * @param context Context * @param data 数据 * @return 是否成功 */ public boolean copy(Context context, Object data) { if (mMatcher == null) return false; final int count = getAdapterCount(); if (count <= 0) return false; for (int i = 0; i < count; i++) { final Adapter adapter = getAdapter(i); if (adapter == null) continue; if (adapter.canCopy(context, data)) { final ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (manager == null) return false; final Uri uri = Uri.parse("content://" + getAuthority() + "/" + getPath() + "/" + adapter.getSubType()); if (onCopy(context, data, uri, adapter)) { ClipData clip = ClipData.newUri(context.getContentResolver(), "URI", uri); manager.setPrimaryClip(clip); return true; } } } return false; }
Example 7
Source File: Global.java From OneTapVideoDownload with GNU General Public License v3.0 | 4 votes |
public static void copyUrlToClipboard(Context context, String url) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); Uri copyUri = Uri.parse(url); ClipData clip = ClipData.newUri(context.getContentResolver(), "URI", copyUri); clipboard.setPrimaryClip(clip); }
Example 8
Source File: PictureUploadPopUpFragment.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void imageCapture() { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (!(getActivity() instanceof MobicomkitUriListener)) { Utils.printLog(getContext(),TAG, "Activity must implement MobicomkitUriListener to get image file uri"); return; } if (cameraIntent.resolveActivity(getContext().getPackageManager()) != null) { Uri capturedImageUri = ((MobicomkitUriListener) getActivity()).getCurrentImageUri(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = ClipData.newUri(getActivity().getContentResolver(), "a Photo", capturedImageUri); cameraIntent.setClipData(clip); cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { List<ResolveInfo> resInfoList = getActivity().getPackageManager() .queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; getActivity().grantUriPermission(packageName, capturedImageUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); getActivity().grantUriPermission(packageName, capturedImageUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); } } cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri); getActivity().startActivityForResult(cameraIntent, ProfileFragment.REQUEST_CODE_TAKE_PHOTO); } }
Example 9
Source File: FullScreenImageActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { int i = item.getItemId(); if (i == R.id.shareOptions) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); Uri uri = ALFileProvider.getUriForFile(this, Utils.getMetaDataValue(this, MobiComKitConstants.PACKAGE_NAME) + ".applozic.provider", new File(message.getFilePaths().get(0))); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = ClipData.newUri(getContentResolver(), "a Photo", uri); shareIntent.setClipData(clip); shareIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { List<ResolveInfo> resInfoList = getPackageManager() .queryIntentActivities(shareIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); } } shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType(FileUtils.getMimeType(new File(message.getFilePaths().get(0)))); startActivity(Intent.createChooser(shareIntent, "")); } else if (i == R.id.forward) { Intent intent = new Intent(); intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class)); setResult(RESULT_OK, intent); this.finish(); return true; } return super.onOptionsItemSelected(item); }
Example 10
Source File: ConversationActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void imageCapture() { try { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_" + ".jpeg"; mediaFile = FileClientService.getFilePath(imageFileName, getApplicationContext(), "image/jpeg"); capturedImageUri = ALFileProvider.getUriForFile(this, Utils.getMetaDataValue(this, MobiComKitConstants.PACKAGE_NAME) + ".applozic.provider", mediaFile); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = ClipData.newUri(getContentResolver(), "a Photo", capturedImageUri); cameraIntent.setClipData(clip); cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { List<ResolveInfo> resInfoList = getPackageManager() .queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, capturedImageUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); grantUriPermission(packageName, capturedImageUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); } } if (cameraIntent.resolveActivity(getApplicationContext().getPackageManager()) != null) { if (mediaFile != null) { startActivityForResult(cameraIntent, MultimediaOptionFragment.REQUEST_CODE_TAKE_PHOTO); } } } catch (Exception e) { e.printStackTrace(); } }
Example 11
Source File: ConversationActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void showVideoCapture() { try { Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "VID_" + timeStamp + "_" + ".mp4"; mediaFile = FileClientService.getFilePath(imageFileName, getApplicationContext(), "video/mp4"); videoFileUri = ALFileProvider.getUriForFile(this, Utils.getMetaDataValue(this, MobiComKitConstants.PACKAGE_NAME) + ".applozic.provider", mediaFile); videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, videoFileUri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { videoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); videoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData clip = ClipData.newUri(getContentResolver(), "a Video", videoFileUri); videoIntent.setClipData(clip); videoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); videoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { List<ResolveInfo> resInfoList = getPackageManager() .queryIntentActivities(videoIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, videoFileUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION); grantUriPermission(packageName, videoFileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); } } if (videoIntent.resolveActivity(getApplicationContext().getPackageManager()) != null) { if (mediaFile != null) { videoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); startActivityForResult(videoIntent, MultimediaOptionFragment.REQUEST_CODE_CAPTURE_VIDEO_ACTIVITY); } } } catch (Exception e) { e.printStackTrace(); } }