List of usage examples for android.content Intent setClipData
public void setClipData(@Nullable ClipData clip)
From source file:com.android.messaging.ui.UIIntentsImpl.java
/** * Get an intent which takes you to a conversation *//* w w w . jav a2s. com*/ private Intent getConversationActivityIntent(final Context context, final String conversationId, final MessageData draft, final boolean withCustomTransition) { final Intent intent = new Intent(context, ConversationActivity.class); // Always try to reuse the same ConversationActivity in the current task so that we don't // have two conversation activities in the back stack. intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Otherwise we're starting a new conversation if (conversationId != null) { intent.putExtra(UI_INTENT_EXTRA_CONVERSATION_ID, conversationId); } if (draft != null) { intent.putExtra(UI_INTENT_EXTRA_DRAFT_DATA, draft); // If draft attachments came from an external content provider via a share intent, we // need to propagate the URI permissions through to ConversationActivity. This requires // putting the URIs into the ClipData (setData also works, but accepts only one URI). ClipData clipData = null; for (final MessagePartData partData : draft.getParts()) { if (partData.isAttachment()) { final Uri uri = partData.getContentUri(); if (clipData == null) { clipData = ClipData.newRawUri("Attachments", uri); } else { clipData.addItem(new ClipData.Item(uri)); } } } if (clipData != null) { intent.setClipData(clipData); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } } if (withCustomTransition) { intent.putExtra(UI_INTENT_EXTRA_WITH_CUSTOM_TRANSITION, true); } if (!(context instanceof Activity)) { // If the caller supplies an application context, and not an activity context, we must // include this flag intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } return intent; }
From source file:org.kontalk.ui.AbstractComposeFragment.java
/** Starts an activity for shooting a picture. */ void selectPhotoAttachment() { try {//from w w w . j a v a 2 s. co m // check if camera is available final PackageManager packageManager = getActivity().getPackageManager(); final Intent intent = SystemUtils.externalIntent(MediaStore.ACTION_IMAGE_CAPTURE); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (list.size() <= 0) throw new UnsupportedOperationException(); mCurrentPhoto = MediaStorage.getOutgoingPhotoFile(); Uri uri = Uri.fromFile(mCurrentPhoto); Intent take = SystemUtils.externalIntent(MediaStore.ACTION_IMAGE_CAPTURE); take.putExtra(MediaStore.EXTRA_OUTPUT, uri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { take.setClipData(ClipData.newUri(getContext().getContentResolver(), "Picture path", uri)); } startActivityForResult(take, SELECT_ATTACHMENT_PHOTO); } catch (UnsupportedOperationException ue) { Toast.makeText(getActivity(), R.string.chooser_error_no_camera_app, Toast.LENGTH_LONG).show(); } catch (IOException e) { Log.e(TAG, "error creating temp file", e); Toast.makeText(getActivity(), R.string.chooser_error_no_camera, Toast.LENGTH_LONG).show(); } }
From source file:org.kontalk.ui.ComposeMessageFragment.java
/** Starts an activity for shooting a picture. */ private void selectPhotoAttachment() { try {/*from ww w . j av a 2 s. c om*/ // check if camera is available final PackageManager packageManager = getActivity().getPackageManager(); final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (list.size() <= 0) throw new UnsupportedOperationException(); mCurrentPhoto = MediaStorage.getOutgoingImageFile(); Uri uri = Uri.fromFile(mCurrentPhoto); Intent take = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); take.putExtra(MediaStore.EXTRA_OUTPUT, uri); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { take.setClipData(ClipData.newUri(getContext().getContentResolver(), "Picture path", uri)); } startActivityForResult(take, SELECT_ATTACHMENT_PHOTO); } catch (UnsupportedOperationException ue) { Toast.makeText(getActivity(), R.string.chooser_error_no_camera_app, Toast.LENGTH_LONG).show(); } catch (IOException e) { Log.e(TAG, "error creating temp file", e); Toast.makeText(getActivity(), R.string.chooser_error_no_camera, Toast.LENGTH_LONG).show(); } }
From source file:com.android.mail.compose.ComposeActivity.java
protected void sendOrSave(final boolean save, final boolean showToast) { // Check if user is a monkey. Monkeys can compose and hit send // button but are not allowed to send anything off the device. if (ActivityManager.isUserAMonkey()) { return;/* w w w.j a v a 2 s . co m*/ } final SendOrSaveCallback callback = new SendOrSaveCallback() { @Override public void initializeSendOrSave() { final Intent i = new Intent(ComposeActivity.this, EmptyService.class); // API 16+ allows for setClipData. For pre-16 we are going to open the fds // on the main thread. if (Utils.isRunningJellybeanOrLater()) { // Grant the READ permission for the attachments to the service so that // as long as the service stays alive we won't hit PermissionExceptions. final ClipDescription desc = new ClipDescription("attachment_uris", new String[] { ClipDescription.MIMETYPE_TEXT_URILIST }); ClipData clipData = null; for (Attachment a : mAttachmentsView.getAttachments()) { if (a != null && !Utils.isEmpty(a.contentUri)) { final ClipData.Item uriItem = new ClipData.Item(a.contentUri); if (clipData == null) { clipData = new ClipData(desc, uriItem); } else { clipData.addItem(uriItem); } } } i.setClipData(clipData); i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } synchronized (PENDING_SEND_OR_SAVE_TASKS_NUM) { if (PENDING_SEND_OR_SAVE_TASKS_NUM.getAndAdd(1) == 0) { // Start service so we won't be killed if this app is // put in the background. startService(i); } } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.initializeSendOrSave(); } } @Override public void notifyMessageIdAllocated(SendOrSaveMessage sendOrSaveMessage, Message message) { synchronized (mDraftLock) { mDraftId = message.id; mDraft = message; if (sRequestMessageIdMap != null) { sRequestMessageIdMap.put(sendOrSaveMessage.mRequestId, mDraftId); } // Cache request message map, in case the process is killed saveRequestMap(); } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.notifyMessageIdAllocated(sendOrSaveMessage, message); } } @Override public long getMessageId() { synchronized (mDraftLock) { return mDraftId; } } @Override public void sendOrSaveFinished(SendOrSaveMessage message, boolean success) { // Update the last sent from account. if (mAccount != null) { MailAppProvider.getInstance().setLastSentFromAccount(mAccount.uri.toString()); } if (success) { // Successfully sent or saved so reset change markers discardChanges(); } else { // A failure happened with saving/sending the draft // TODO(pwestbro): add a better string that should be used // when failing to send or save Toast.makeText(ComposeActivity.this, R.string.send_failed, Toast.LENGTH_SHORT).show(); } synchronized (PENDING_SEND_OR_SAVE_TASKS_NUM) { if (PENDING_SEND_OR_SAVE_TASKS_NUM.addAndGet(-1) == 0) { // Stop service so we can be killed. stopService(new Intent(ComposeActivity.this, EmptyService.class)); } } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.sendOrSaveFinished(message, success); } } }; setAccount(mReplyFromAccount.account); final Spanned body = removeComposingSpans(mBodyView.getText()); callback.initializeSendOrSave(); // For pre-JB we need to open the fds on the main thread final Bundle attachmentFds; if (!Utils.isRunningJellybeanOrLater()) { attachmentFds = initializeAttachmentFds(this, mAttachmentsView.getAttachments()); } else { attachmentFds = null; } // Generate a unique message id for this request mRequestId = sRandom.nextInt(); SEND_SAVE_TASK_HANDLER.post(new Runnable() { @Override public void run() { final Message msg = createMessage(mReplyFromAccount, mRefMessage, getMode(), body); sendOrSaveInternal(ComposeActivity.this, mRequestId, mReplyFromAccount, mDraftAccount, msg, mRefMessage, mQuotedTextView.getQuotedTextIfIncluded(), callback, save, mComposeMode, mExtraValues, attachmentFds); } }); // Don't display the toast if the user is just changing the orientation, // but we still need to save the draft to the cursor because this is how we restore // the attachments when the configuration change completes. if (showToast && (getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) { Toast.makeText(this, save ? R.string.message_saved : R.string.sending_message, Toast.LENGTH_LONG) .show(); } // Need to update variables here because the send or save completes // asynchronously even though the toast shows right away. discardChanges(); updateSaveUi(); // If we are sending, finish the activity if (!save) { finish(); } }