List of usage examples for android.content Intent getClipData
public @Nullable ClipData getClipData()
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == ZOOZ_PAYMENT) { ((IntentResultListener) pur).onActivityResult(requestCode, resultCode, intent); return;//from w w w.j a va 2s.c o m } if (resultCode == Activity.RESULT_OK) { if (requestCode == CAPTURE_IMAGE) { try { String imageUri = (String) Storage.getInstance().readObject("imageUri"); Vector pathandId = StringUtil.tokenizeString(imageUri, ";"); String path = (String) pathandId.get(0); String lastId = (String) pathandId.get(1); Storage.getInstance().deleteStorageFile("imageUri"); clearMediaDB(lastId, path); callback.fireActionEvent(new ActionEvent(path)); return; } catch (Exception e) { e.printStackTrace(); } } else if (requestCode == CAPTURE_VIDEO) { String path = (String) Storage.getInstance().readObject("videoUri"); Storage.getInstance().deleteStorageFile("videoUri"); callback.fireActionEvent(new ActionEvent(path)); return; } else if (requestCode == CAPTURE_AUDIO) { Uri data = intent.getData(); String path = convertImageUriToFilePath(data, getContext()); callback.fireActionEvent(new ActionEvent(path)); return; } else if (requestCode == OPEN_GALLERY_MULTI) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (intent.getClipData() != null) { // If it was a multi-request ArrayList<String> selectedPaths = new ArrayList<String>(); int count = intent.getClipData().getItemCount(); for (int i = 0; i < count; i++) { Uri uri = intent.getClipData().getItemAt(i).getUri(); String p = getImageFilePath(uri); if (p != null) { selectedPaths.add(p); } } callback.fireActionEvent( new ActionEvent(selectedPaths.toArray(new String[selectedPaths.size()]))); return; } } else { com.codename1.io.Log.e(new RuntimeException( "OPEN_GALLERY_MULTI requires android sdk 16 (jelly bean) or higher")); callback.fireActionEvent(null); } Uri selectedImage = intent.getData(); String scheme = intent.getScheme(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null); // this happens on Android devices, not exactly sure what the use case is if (cursor == null) { callback.fireActionEvent(null); return; } cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); if (filePath == null && "content".equals(scheme)) { //if the file is not on the filesystem download it and save it //locally try { InputStream inputStream = getContext().getContentResolver().openInputStream(selectedImage); if (inputStream != null) { String name = getContentName(getContext().getContentResolver(), selectedImage); if (name != null) { filePath = getAppHomePath() + getFileSystemSeparator() + name; File f = new File(removeFilePrefix(filePath)); OutputStream tmp = createFileOuputStream(f); byte[] buffer = new byte[1024]; int read = -1; while ((read = inputStream.read(buffer)) > -1) { tmp.write(buffer, 0, read); } tmp.close(); inputStream.close(); } } } catch (Exception e) { e.printStackTrace(); } } callback.fireActionEvent(new ActionEvent(new String[] { filePath })); return; } else if (requestCode == OPEN_GALLERY) { Uri selectedImage = intent.getData(); String scheme = intent.getScheme(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null); // this happens on Android devices, not exactly sure what the use case is if (cursor == null) { callback.fireActionEvent(null); return; } cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String filePath = cursor.getString(columnIndex); cursor.close(); if (filePath == null && "content".equals(scheme)) { //if the file is not on the filesystem download it and save it //locally try { InputStream inputStream = getContext().getContentResolver().openInputStream(selectedImage); if (inputStream != null) { String name = getContentName(getContext().getContentResolver(), selectedImage); if (name != null) { filePath = getAppHomePath() + getFileSystemSeparator() + name; File f = new File(removeFilePrefix(filePath)); OutputStream tmp = createFileOuputStream(f); byte[] buffer = new byte[1024]; int read = -1; while ((read = inputStream.read(buffer)) > -1) { tmp.write(buffer, 0, read); } tmp.close(); inputStream.close(); } } } catch (Exception e) { e.printStackTrace(); } } callback.fireActionEvent(new ActionEvent(filePath)); return; } else { if (callback != null) { callback.fireActionEvent(new ActionEvent("ok")); } return; } } //clean imageUri String imageUri = (String) Storage.getInstance().readObject("imageUri"); if (imageUri != null) { Storage.getInstance().deleteStorageFile("imageUri"); } if (callback != null) { callback.fireActionEvent(null); } }
From source file:com.tct.mail.compose.ComposeActivity.java
private void finishCreate() { final Bundle savedState = mInnerSavedState; findViews();//from w ww . ja v a 2 s.c o m // TS: junwei-xu 2015-09-01 EMAIL BUGFIX-526192 ADD_S updateFromRowByAccounts(); // TS: junwei-xu 2015-09-01 EMAIL BUGFIX-526192 ADD_E final Intent intent = getIntent(); final Message message; final ArrayList<AttachmentPreview> previews; mShowQuotedText = false; final CharSequence quotedText; int action; // Check for any of the possibly supplied accounts.; final Account account; if (hadSavedInstanceStateMessage(savedState)) { action = savedState.getInt(EXTRA_ACTION, COMPOSE); account = savedState.getParcelable(Utils.EXTRA_ACCOUNT); message = savedState.getParcelable(EXTRA_MESSAGE); previews = savedState.getParcelableArrayList(EXTRA_ATTACHMENT_PREVIEWS); mRefMessage = savedState.getParcelable(EXTRA_IN_REFERENCE_TO_MESSAGE); quotedText = savedState.getCharSequence(EXTRA_QUOTED_TEXT); mExtraValues = savedState.getParcelable(EXTRA_VALUES); } else { account = obtainAccount(intent); action = intent.getIntExtra(EXTRA_ACTION, COMPOSE); // Initialize the message from the message in the intent message = intent.getParcelableExtra(ORIGINAL_DRAFT_MESSAGE); previews = intent.getParcelableArrayListExtra(EXTRA_ATTACHMENT_PREVIEWS); mRefMessage = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE); //TS: wenggangjin 2015-01-06 EMAIL BUGFIX_882161 MOD_S if (mRefMessage != null && "".equals(mRefMessage.bodyHtml)) { String htmlbody = Body.restoreBodyHtmlWithMessageId(this, mRefMessage.getId()); mRefMessage.bodyHtml = htmlbody; //TS: xujian 2015-06-23 EMAIL BUGFIX_1015657 MOD_S } else if (message != null) { if ("".equals(message.bodyHtml)) { String htmlbody = Body.restoreBodyHtmlWithMessageId(this, message.getId()); message.bodyHtml = htmlbody; } if ("".equals(message.bodyText)) { String body = Body.restoreBodyTextWithMessageId(this, message.getId()); message.bodyText = body; } //TS: xujian 2015-06-23 EMAIL BUGFIX_1015657 MOD_S } //TS: wenggangjin 2015-01-06 EMAIL BUGFIX_882161 MOD_E mRefMessageUri = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE_URI); quotedText = null; if (Analytics.isLoggable()) { if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) { Analytics.getInstance().sendEvent("notification_action", "compose", getActionString(action), 0); } } } //TS: Gantao 2015-08-27 EMAIL FEATURE_ID DEL_S // mAttachmentsView.setAttachmentPreviews(previews); //TS: Gantao 2015-08-27 EMAIL FEATURE_ID DEL_E // TS: yanhua.chen 2015-9-19 EMAIL BUGFIX_569665 ADD_S if (action == EDIT_DRAFT) { //mIsClickIcon = true;//[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,05/06/2016,2013535 mEditDraft = true; } // TS: yanhua.chen 2015-9-19 EMAIL BUGFIX_569665 ADD_E setAccount(account); if (mAccount == null) { return; } // TS: chenyanhua 2015-01-12 EMAIL BUGFIX-890424 MOD_S // initRecipients(); // TS: chenyanhua 2015-01-12 EMAIL BUGFIX-890424 MOD_S // Clear the notification and mark the conversation as seen, if necessary final Folder notificationFolder = intent.getParcelableExtra(EXTRA_NOTIFICATION_FOLDER); if (notificationFolder != null) { final Uri conversationUri = intent.getParcelableExtra(EXTRA_NOTIFICATION_CONVERSATION); Intent actionIntent; if (conversationUri != null) { actionIntent = new Intent(MailIntentService.ACTION_RESEND_NOTIFICATIONS_WEAR); actionIntent.putExtra(Utils.EXTRA_CONVERSATION, conversationUri); } else { actionIntent = new Intent(MailIntentService.ACTION_CLEAR_NEW_MAIL_NOTIFICATIONS); actionIntent.setData(Utils.appendVersionQueryParameter(this, notificationFolder.folderUri.fullUri)); } actionIntent.setPackage(getPackageName()); actionIntent.putExtra(Utils.EXTRA_ACCOUNT, account); actionIntent.putExtra(Utils.EXTRA_FOLDER, notificationFolder); startService(actionIntent); } if (intent.getBooleanExtra(EXTRA_FROM_EMAIL_TASK, false)) { mLaunchedFromEmail = true; } else if (Intent.ACTION_SEND.equals(intent.getAction())) { final Uri dataUri = intent.getData(); if (dataUri != null) { final String dataScheme = intent.getData().getScheme(); final String accountScheme = mAccount.composeIntentUri.getScheme(); mLaunchedFromEmail = TextUtils.equals(dataScheme, accountScheme); } } if (mRefMessageUri != null) { mShowQuotedText = true; mComposeMode = action; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); String wearReply = null; if (remoteInput != null) { LogUtils.d(LOG_TAG, "Got remote input from new api"); CharSequence input = remoteInput.getCharSequence(NotificationActionUtils.WEAR_REPLY_INPUT); if (input != null) { wearReply = input.toString(); } } else { // TODO: remove after legacy code has been removed. LogUtils.d(LOG_TAG, "No remote input from new api, falling back to compatibility mode"); ClipData clipData = intent.getClipData(); if (clipData != null && LEGACY_WEAR_EXTRA.equals(clipData.getDescription().getLabel())) { Bundle extras = clipData.getItemAt(0).getIntent().getExtras(); if (extras != null) { wearReply = extras.getString(NotificationActionUtils.WEAR_REPLY_INPUT); } } } if (!TextUtils.isEmpty(wearReply)) { createWearReplyTask(this, mRefMessageUri, UIProvider.MESSAGE_PROJECTION, mComposeMode, wearReply).execute(); finish(); return; } else { LogUtils.w(LOG_TAG, "remote input string is null"); } } getLoaderManager().initLoader(INIT_DRAFT_USING_REFERENCE_MESSAGE, null, this); return; } else if (message != null && action != EDIT_DRAFT) { initFromDraftMessage(message); initQuotedTextFromRefMessage(mRefMessage, action); mShowQuotedText = message.appendRefMessageContent; // if we should be showing quoted text but mRefMessage is null // and we have some quotedText, display that if (mShowQuotedText && mRefMessage == null) { if (quotedText != null) { initQuotedText(quotedText, false /* shouldQuoteText */); } else if (mExtraValues != null) { initExtraValues(mExtraValues); return; } } } else if (action == EDIT_DRAFT) { if (message == null) { throw new IllegalStateException("Message must not be null to edit draft"); } initFromDraftMessage(message); // Update the action to the draft type of the previous draft switch (message.draftType) { case UIProvider.DraftType.REPLY: action = REPLY; break; case UIProvider.DraftType.REPLY_ALL: action = REPLY_ALL; break; case UIProvider.DraftType.FORWARD: action = FORWARD; break; case UIProvider.DraftType.COMPOSE: default: action = COMPOSE; break; } LogUtils.d(LOG_TAG, "Previous draft had action type: %d", action); mShowQuotedText = message.appendRefMessageContent; //TS: Gantao 2015-07-28 EMAIL BUGFIX_1053829 MOD_S //Terrible original design,refMessageUri did not save to db,the value is always 0 here. //but the body's sourceKey is saved ,it points to the refMessage's id,so we can get //the refMessage from the body's sourceKey. long sourceKey = Body.restoreBodySourceKey(this, message.id); if (sourceKey != 0) { // If we're editing an existing draft that was in reference to an existing message, // still need to load that original message since we might need to refer to the // original sender and recipients if user switches "reply <-> reply-all". mRefMessageUri = Uri.parse("content://" + EmailContent.AUTHORITY + "/uimessage/" + sourceKey); //TS: Gantao 2015-07-28 EMAIL BUGFIX_1053829 MOD_E mComposeMode = action; getLoaderManager().initLoader(REFERENCE_MESSAGE_LOADER, null, this); return; } } else if ((action == REPLY || action == REPLY_ALL || action == FORWARD)) { if (mRefMessage != null) { initFromRefMessage(action); mShowQuotedText = true; } } else { if (initFromExtras(intent)) { return; } } mComposeMode = action; finishSetup(action, intent, savedState); }