List of usage examples for android.content Intent EXTRA_STREAM
String EXTRA_STREAM
To view the source code for android.content Intent EXTRA_STREAM.
Click Source Link
From source file:com.tct.mail.compose.ComposeActivity.java
private void initAttachmentsFromIntent(Intent intent) { Bundle extras = intent.getExtras();/* www . jav a2s .c om*/ if (extras == null) { extras = Bundle.EMPTY; } final String action = intent.getAction(); if (!mAttachmentsChanged) { long totalSize = 0; if (extras.containsKey(EXTRA_ATTACHMENTS)) { String[] uris = (String[]) extras.getSerializable(EXTRA_ATTACHMENTS); for (String uriString : uris) { final Uri uri = Uri.parse(uriString); long size = 0; try { if (handleSpecialAttachmentUri(uri)) { continue; } final Attachment a = mAttachmentsView.generateLocalAttachment(uri); //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_S if (a == null) { continue; } //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_E size = mAttachmentsView.addAttachment(mAccount, a, true);//TS: yanhua.chen 2015-6-8 EMAIL CR_996908 MOD Analytics.getInstance().sendEvent("send_intent_attachment", Utils.normalizeMimeType(a.getContentType()), null, size); } catch (AttachmentFailureException e) { LogUtils.e(LOG_TAG, e, "Error adding attachment"); showAttachmentTooBigToast(e.getErrorRes()); } totalSize += size; } } if (extras.containsKey(Intent.EXTRA_STREAM)) { if (!PermissionUtil.checkAndRequestPermissionForResult(this, Manifest.permission.READ_EXTERNAL_STORAGE, PermissionUtil.REQ_CODE_PERMISSION_ADD_ATTACHMENT)) { return; } if (Intent.ACTION_SEND_MULTIPLE.equals(action)) { final ArrayList<Uri> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM); ArrayList<Attachment> attachments = new ArrayList<Attachment>(); for (Uri uri : uris) { if (uri == null) { continue; } try { if (handleSpecialAttachmentUri(uri)) { continue; } final Attachment a = mAttachmentsView.generateLocalAttachment(uri); //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_S if (a == null) { continue; } //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_E attachments.add(a); Analytics.getInstance().sendEvent("send_intent_attachment", Utils.normalizeMimeType(a.getContentType()), null, a.size); } catch (AttachmentFailureException e) { LogUtils.e(LOG_TAG, e, "Error adding attachment"); String maxSize = AttachmentUtils.convertToHumanReadableSize(getApplicationContext(), mAccount.settings.getMaxAttachmentSize()); showErrorToast(getString(R.string.generic_attachment_problem, maxSize)); } } // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_S totalSize += addAttachments(attachments, false); // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_E } else { final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM); if (uri != null) { long size = 0; //[BUGFIX]-Modified-BEGIN by TCTNJ.wenlu.wu,12/03/2014,PR-857886 if (!handleSpecialAttachmentUri(uri)) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { Attachment mAttachment = mAttachmentsView.generateLocalAttachment(uri); android.os.Message msg = new android.os.Message(); msg.what = 1001; msg.obj = mAttachment; mHandler.sendMessage(msg); } catch (AttachmentFailureException e) { LogUtils.e(LOG_TAG, e, "Error adding attachment"); showAttachmentTooBigToast(e.getErrorRes()); } return null; } @Override protected void onPostExecute(Void result) { } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } //[BUGFIX]-Modified-END by TCTNJ.wenlu.wu,12/03/2014,PR-857886 totalSize += size; } } } if (totalSize > 0) { mAttachmentsChanged = true; updateSaveUi(); Analytics.getInstance().sendEvent("send_intent_with_attachments", Integer.toString(getAttachments().size()), null, totalSize); } } }
From source file:com.tct.mail.compose.ComposeActivity.java
private int getShareAttachmentSize(Intent intent) { Bundle extras = intent.getExtras();/*from w ww . ja v a 2 s . c o m*/ if (extras == null) { extras = Bundle.EMPTY; } final String action = intent.getAction(); int totalSize = 0; if (Intent.ACTION_SEND_MULTIPLE.equals(action)) { final ArrayList<Uri> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM); ArrayList<Attachment> attachments = new ArrayList<Attachment>(); for (Uri uri : uris) { if (uri == null) { continue; } try { if (handleSpecialAttachmentUri(uri)) { continue; } final Attachment a = mAttachmentsView.generateLocalAttachment(uri); //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_S if (a == null) { continue; } //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_E attachments.add(a); Analytics.getInstance().sendEvent("send_intent_attachment", Utils.normalizeMimeType(a.getContentType()), null, a.size); } catch (AttachmentFailureException e) { LogUtils.e(LOG_TAG, e, "Error adding attachment"); String maxSize = AttachmentUtils.convertToHumanReadableSize(getApplicationContext(), mAccount.settings.getMaxAttachmentSize()); showErrorToast(getString(R.string.generic_attachment_problem, maxSize)); } } // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_S totalSize += addAttachments(attachments, false); // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_E } else { final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM); if (uri != null) { long size = 0; //[BUGFIX]-Modified-BEGIN by TCTNJ.wenlu.wu,12/03/2014,PR-857886 if (!handleSpecialAttachmentUri(uri)) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { Attachment mAttachment = mAttachmentsView.generateLocalAttachment(uri); android.os.Message msg = new android.os.Message(); msg.what = ADD_ATTACHMENT_MSG; msg.obj = mAttachment; mHandler.sendMessage(msg); } catch (AttachmentFailureException e) { LogUtils.e(LOG_TAG, e, "Error adding attachment"); // TS: jian.xu 2016-01-11 EMAIL BUGFIX-1307962 MOD_S //Note: show toast must be on ui thread. android.os.Message errorMsg = new android.os.Message(); errorMsg.what = ADD_ATTACHMENT_MSG_ERROR; errorMsg.obj = e.getErrorRes(); mHandler.sendMessage(errorMsg); //showAttachmentTooBigToast(e.getErrorRes()); // TS: jian.xu 2016-01-11 EMAIL BUGFIX-1307962 MOD_E } return null; } @Override protected void onPostExecute(Void result) { } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } //[BUGFIX]-Modified-END by TCTNJ.wenlu.wu,12/03/2014,PR-857886 totalSize += size; } } return totalSize; }
From source file:com.codename1.impl.android.AndroidImplementation.java
/** * @inheritDoc/* w ww .j a v a 2s. co m*/ */ public void sendMessage(String[] recipients, String subject, Message msg) { if (editInProgress()) { stopEditing(true); } Intent emailIntent; String attachment = msg.getAttachment(); boolean hasAttachment = (attachment != null && attachment.length() > 0) || msg.getAttachments().size() > 0; if (msg.getMimeType().equals(Message.MIME_TEXT) && !hasAttachment) { StringBuilder to = new StringBuilder(); for (int i = 0; i < recipients.length; i++) { to.append(recipients[i]); to.append(";"); } emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + to.toString() + "?subject=" + Uri.encode(subject) + "&body=" + Uri.encode(msg.getContent()))); } else { if (hasAttachment) { if (msg.getAttachments().size() > 1) { emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); emailIntent.setType(msg.getMimeType()); ArrayList<Uri> uris = new ArrayList<Uri>(); for (String path : msg.getAttachments().keySet()) { uris.add(Uri.parse(fixAttachmentPath(path))); } emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } else { emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); emailIntent.setType(msg.getMimeType()); emailIntent.setType(msg.getAttachmentMimeType()); //if the attachment is in the uder home dir we need to copy it //to an accessible dir attachment = fixAttachmentPath(attachment); emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(attachment)); } } else { emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); emailIntent.setType(msg.getMimeType()); } if (msg.getMimeType().equals(Message.MIME_HTML)) { emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(msg.getContent())); } else { /* // Attempted this workaround to fix the ClassCastException that occurs on android when // there are multiple attachments. Unfortunately, this fixes the stack trace, but // has the unwanted side-effect of producing a blank message body. // Same workaround for HTML mimetype also fails the same way. // Conclusion, Just live with the stack trace. It doesn't seem to affect the // execution of the program... treat it as a warning. // See https://github.com/codenameone/CodenameOne/issues/1782 if (msg.getAttachments().size() > 1) { ArrayList<String> contentArr = new ArrayList<String>(); contentArr.add(msg.getContent()); emailIntent.putStringArrayListExtra(android.content.Intent.EXTRA_TEXT, contentArr); } else { emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent()); }*/ emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent()); } } final String attach = attachment; AndroidNativeUtil.startActivityForResult(Intent.createChooser(emailIntent, "Send mail..."), new IntentResultListener() { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (attach != null && attach.length() > 0 && attach.contains("tmp")) { FileSystemStorage.getInstance().delete(attach); } } }); }
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public void share(String text, String image, String mimeType, Rectangle sourceRect) { /*if(!checkForPermission(Manifest.permission.READ_PHONE_STATE, "This is required to perform share")){ return;//from w ww . j av a2 s . com }*/ Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); if (image == null) { shareIntent.setType("text/plain"); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, text); } else { shareIntent.setType(mimeType); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(fixAttachmentPath(image))); shareIntent.putExtra(Intent.EXTRA_TEXT, text); } getContext().startActivity(Intent.createChooser(shareIntent, "Share with...")); }
From source file:net.bluehack.ui.ChatActivity.java
private void processSelectedOption(int option) { if (selectedObject == null) { return;//w w w . j a v a 2 s . c om } switch (option) { case 0: { if (SendMessagesHelper.getInstance().retrySendMessage(selectedObject, false)) { moveScrollToLastMessage(); } break; } case 1: { if (getParentActivity() == null) { selectedObject = null; return; } createDeleteMessagesAlert(selectedObject); break; } case 2: { forwaringMessage = selectedObject; Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putInt("dialogsType", 1); DialogsActivity fragment = new DialogsActivity(args); fragment.setDelegate(this); presentFragment(fragment); break; } case 3: { AndroidUtilities.addToClipboard(getMessageContent(selectedObject, 0, false)); break; } case 4: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } if (selectedObject.type == 3 || selectedObject.type == 1) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity() .requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } MediaController.saveFile(path, getParentActivity(), selectedObject.type == 3 ? 1 : 0, null, null); } break; } case 5: { File locFile = null; if (selectedObject.messageOwner.attachPath != null && selectedObject.messageOwner.attachPath.length() != 0) { File f = new File(selectedObject.messageOwner.attachPath); if (f.exists()) { locFile = f; } } if (locFile == null) { File f = FileLoader.getPathToMessage(selectedObject.messageOwner); if (f.exists()) { locFile = f; } } if (locFile != null) { if (LocaleController.getInstance().applyLanguageFile(locFile)) { presentFragment(new LanguageSelectActivity()); } else { if (getParentActivity() == null) { selectedObject = null; return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage( LocaleController.getString("IncorrectLocalization", R.string.IncorrectLocalization)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); showDialog(builder.create()); } } break; } case 6: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType(selectedObject.getDocument().mime_type); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path))); getParentActivity().startActivityForResult( Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500); break; } case 7: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } MediaController.saveFile(path, getParentActivity(), 0, null, null); break; } case 8: { showReplyPanel(true, selectedObject, null, null, false, true); break; } case 9: { showDialog(new StickersAlert(getParentActivity(), this, selectedObject.getInputStickerSet(), null, bottomOverlayChat.getVisibility() != View.VISIBLE ? chatActivityEnterView : null)); break; } case 10: { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } String fileName = FileLoader.getDocumentFileName(selectedObject.getDocument()); if (fileName == null || fileName.length() == 0) { fileName = selectedObject.getFileName(); } String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } MediaController.saveFile(path, getParentActivity(), selectedObject.isMusic() ? 3 : 2, fileName, selectedObject.getDocument() != null ? selectedObject.getDocument().mime_type : ""); break; } case 11: { TLRPC.Document document = selectedObject.getDocument(); MessagesController.getInstance().saveGif(document); showGifHint(); chatActivityEnterView.addRecentGif(document); break; } case 12: { if (getParentActivity() == null) { selectedObject = null; return; } if (searchItem != null && actionBar.isSearchFieldVisible()) { actionBar.closeSearchField(); chatActivityEnterView.setFieldFocused(); } mentionsAdapter.setNeedBotContext(false); chatListView.setOnItemLongClickListener(null); chatListView.setOnItemClickListener(null); chatListView.setClickable(false); chatListView.setLongClickable(false); chatActivityEnterView.setEditingMessageObject(selectedObject, !selectedObject.isMediaEmpty()); if (chatActivityEnterView.isEditingCaption()) { mentionsAdapter.setAllowNewMentions(false); } actionModeTitleContainer.setVisibility(View.VISIBLE); selectedMessagesCountTextView.setVisibility(View.GONE); checkEditTimer(); chatActivityEnterView.setAllowStickersAndGifs(false, false); final ActionBarMenu actionMode = actionBar.createActionMode(); actionMode.getItem(reply).setVisibility(View.GONE); actionMode.getItem(copy).setVisibility(View.GONE); actionMode.getItem(forward).setVisibility(View.GONE); actionMode.getItem(delete).setVisibility(View.GONE); if (editDoneItemAnimation != null) { editDoneItemAnimation.cancel(); editDoneItemAnimation = null; } editDoneItem.setVisibility(View.VISIBLE); showEditDoneProgress(true, false); actionBar.showActionMode(); updatePinnedMessageView(true); updateVisibleRows(); TLRPC.TL_messages_getMessageEditData req = new TLRPC.TL_messages_getMessageEditData(); req.peer = MessagesController.getInputPeer((int) dialog_id); req.id = selectedObject.getId(); editingMessageObjectReqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { editingMessageObjectReqId = 0; if (response == null) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage( LocaleController.getString("EditMessageError", R.string.EditMessageError)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); showDialog(builder.create()); if (chatActivityEnterView != null) { chatActivityEnterView.setEditingMessageObject(null, false); } } else { showEditDoneProgress(false, true); } } }); } }); break; } case 13: { final int mid = selectedObject.getId(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("PinMessageAlert", R.string.PinMessageAlert)); final boolean[] checks = new boolean[] { true }; FrameLayout frameLayout = new FrameLayout(getParentActivity()); if (Build.VERSION.SDK_INT >= 21) { frameLayout.setPadding(0, AndroidUtilities.dp(8), 0, 0); } CheckBoxCell cell = new CheckBoxCell(getParentActivity()); cell.setBackgroundResource(R.drawable.list_selector); cell.setText(LocaleController.getString("PinNotify", R.string.PinNotify), "", true, false); cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0); frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 0, 8, 0)); cell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CheckBoxCell cell = (CheckBoxCell) v; checks[0] = !checks[0]; cell.setChecked(checks[0], true); } }); builder.setView(frameLayout); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().pinChannelMessage(currentChat, mid, checks[0]); } }); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); break; } case 14: { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("UnpinMessageAlert", R.string.UnpinMessageAlert)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().pinChannelMessage(currentChat, 0, false); } }); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); break; } case 15: { Bundle args = new Bundle(); args.putInt("user_id", selectedObject.messageOwner.media.user_id); args.putString("phone", selectedObject.messageOwner.media.phone_number); args.putBoolean("addContact", true); presentFragment(new ContactAddActivity(args)); break; } case 16: { AndroidUtilities.addToClipboard(selectedObject.messageOwner.media.phone_number); break; } case 17: { try { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + selectedObject.messageOwner.media.phone_number)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getParentActivity().startActivityForResult(intent, 500); } catch (Exception e) { FileLog.e("tmessages", e); } break; } } selectedObject = null; }
From source file:kr.wdream.ui.ChatActivity.java
private void processSelectedOption(int option) { if (selectedObject == null) { return;//from w w w . j a v a 2s . c om } switch (option) { case 0: { if (SendMessagesHelper.getInstance().retrySendMessage(selectedObject, false)) { moveScrollToLastMessage(); } break; } case 1: { if (getParentActivity() == null) { selectedObject = null; return; } createDeleteMessagesAlert(selectedObject); break; } case 2: { forwaringMessage = selectedObject; Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putInt("dialogsType", 1); DialogsActivity fragment = new DialogsActivity(args); fragment.setDelegate(this); presentFragment(fragment); break; } case 3: { AndroidUtilities.addToClipboard(getMessageContent(selectedObject, 0, false)); break; } case 4: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } if (selectedObject.type == 3 || selectedObject.type == 1) { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity() .requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } MediaController.saveFile(path, getParentActivity(), selectedObject.type == 3 ? 1 : 0, null, null); } break; } case 5: { File locFile = null; if (selectedObject.messageOwner.attachPath != null && selectedObject.messageOwner.attachPath.length() != 0) { File f = new File(selectedObject.messageOwner.attachPath); if (f.exists()) { locFile = f; } } if (locFile == null) { File f = FileLoader.getPathToMessage(selectedObject.messageOwner); if (f.exists()) { locFile = f; } } if (locFile != null) { if (LocaleController.getInstance().applyLanguageFile(locFile)) { presentFragment(new LanguageSelectActivity()); } else { if (getParentActivity() == null) { selectedObject = null; return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setMessage(LocaleController.getString("IncorrectLocalization", kr.wdream.storyshop.R.string.IncorrectLocalization)); builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), null); showDialog(builder.create()); } } break; } case 6: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType(selectedObject.getDocument().mime_type); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path))); getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", kr.wdream.storyshop.R.string.ShareFile)), 500); break; } case 7: { String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } MediaController.saveFile(path, getParentActivity(), 0, null, null); break; } case 8: { showReplyPanel(true, selectedObject, null, null, false, true); break; } case 9: { showDialog(new StickersAlert(getParentActivity(), this, selectedObject.getInputStickerSet(), null, bottomOverlayChat.getVisibility() != View.VISIBLE ? chatActivityEnterView : null)); break; } case 10: { if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { getParentActivity().requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4); selectedObject = null; return; } String fileName = FileLoader.getDocumentFileName(selectedObject.getDocument()); if (fileName == null || fileName.length() == 0) { fileName = selectedObject.getFileName(); } String path = selectedObject.messageOwner.attachPath; if (path != null && path.length() > 0) { File temp = new File(path); if (!temp.exists()) { path = null; } } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } MediaController.saveFile(path, getParentActivity(), selectedObject.isMusic() ? 3 : 2, fileName, selectedObject.getDocument() != null ? selectedObject.getDocument().mime_type : ""); break; } case 11: { TLRPC.Document document = selectedObject.getDocument(); MessagesController.getInstance().saveGif(document); showGifHint(); chatActivityEnterView.addRecentGif(document); break; } case 12: { if (getParentActivity() == null) { selectedObject = null; return; } if (searchItem != null && actionBar.isSearchFieldVisible()) { actionBar.closeSearchField(); chatActivityEnterView.setFieldFocused(); } mentionsAdapter.setNeedBotContext(false); chatListView.setOnItemLongClickListener(null); chatListView.setOnItemClickListener(null); chatListView.setClickable(false); chatListView.setLongClickable(false); chatActivityEnterView.setEditingMessageObject(selectedObject, !selectedObject.isMediaEmpty()); if (chatActivityEnterView.isEditingCaption()) { mentionsAdapter.setAllowNewMentions(false); } actionModeTitleContainer.setVisibility(View.VISIBLE); selectedMessagesCountTextView.setVisibility(View.GONE); checkEditTimer(); chatActivityEnterView.setAllowStickersAndGifs(false, false); final ActionBarMenu actionMode = actionBar.createActionMode(); actionMode.getItem(reply).setVisibility(View.GONE); actionMode.getItem(copy).setVisibility(View.GONE); actionMode.getItem(forward).setVisibility(View.GONE); actionMode.getItem(delete).setVisibility(View.GONE); if (editDoneItemAnimation != null) { editDoneItemAnimation.cancel(); editDoneItemAnimation = null; } editDoneItem.setVisibility(View.VISIBLE); showEditDoneProgress(true, false); actionBar.showActionMode(); updatePinnedMessageView(true); updateVisibleRows(); TLRPC.TL_messages_getMessageEditData req = new TLRPC.TL_messages_getMessageEditData(); req.peer = MessagesController.getInputPeer((int) dialog_id); req.id = selectedObject.getId(); editingMessageObjectReqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { editingMessageObjectReqId = 0; if (response == null) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setMessage(LocaleController.getString("EditMessageError", kr.wdream.storyshop.R.string.EditMessageError)); builder.setPositiveButton( LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), null); showDialog(builder.create()); if (chatActivityEnterView != null) { chatActivityEnterView.setEditingMessageObject(null, false); } } else { showEditDoneProgress(false, true); } } }); } }); break; } case 13: { final int mid = selectedObject.getId(); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage( LocaleController.getString("PinMessageAlert", kr.wdream.storyshop.R.string.PinMessageAlert)); final boolean[] checks = new boolean[] { true }; FrameLayout frameLayout = new FrameLayout(getParentActivity()); if (Build.VERSION.SDK_INT >= 21) { frameLayout.setPadding(0, AndroidUtilities.dp(8), 0, 0); } CheckBoxCell cell = new CheckBoxCell(getParentActivity()); cell.setBackgroundResource(kr.wdream.storyshop.R.drawable.list_selector); cell.setText(LocaleController.getString("PinNotify", kr.wdream.storyshop.R.string.PinNotify), "", true, false); cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0); frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 0, 8, 0)); cell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CheckBoxCell cell = (CheckBoxCell) v; checks[0] = !checks[0]; cell.setChecked(checks[0], true); } }); builder.setView(frameLayout); builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().pinChannelMessage(currentChat, mid, checks[0]); } }); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setNegativeButton(LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); break; } case 14: { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("UnpinMessageAlert", kr.wdream.storyshop.R.string.UnpinMessageAlert)); builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().pinChannelMessage(currentChat, 0, false); } }); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setNegativeButton(LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); break; } case 15: { Bundle args = new Bundle(); args.putInt("user_id", selectedObject.messageOwner.media.user_id); args.putString("phone", selectedObject.messageOwner.media.phone_number); args.putBoolean("addContact", true); presentFragment(new ContactAddActivity(args)); break; } case 16: { AndroidUtilities.addToClipboard(selectedObject.messageOwner.media.phone_number); break; } case 17: { try { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + selectedObject.messageOwner.media.phone_number)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getParentActivity().startActivityForResult(intent, 500); } catch (Exception e) { FileLog.e("tmessages", e); } break; } } selectedObject = null; }
From source file:com.zoffcc.applications.zanavi.Navit.java
void sendEmailWithAttachment(Context c, final String recipient, final String subject, final String message, final String full_file_name, final String full_file_name_suppl) { try {/*from w w w . j a v a 2 s . c o m*/ Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", recipient, null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); ArrayList<Uri> uris = new ArrayList<>(); uris.add(Uri.parse("file://" + full_file_name)); try { if (new File(full_file_name_suppl).length() > 0) { uris.add(Uri.parse("file://" + full_file_name_suppl)); } } catch (Exception e) { e.printStackTrace(); } List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(emailIntent, 0); List<LabeledIntent> intents = new ArrayList<>(); if (resolveInfos.size() != 0) { for (ResolveInfo info : resolveInfos) { Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); System.out.println( "email:" + "comp=" + info.activityInfo.packageName + " " + info.activityInfo.name); intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name)); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { recipient }); if (subject != null) intent.putExtra(Intent.EXTRA_SUBJECT, subject); if (message != null) intent.putExtra(Intent.EXTRA_TEXT, message); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); intents.add(new LabeledIntent(intent, info.activityInfo.packageName, info.loadLabel(getPackageManager()), info.icon)); } Intent chooser = Intent.createChooser(intents.remove(intents.size() - 1), Navit.get_text("Send email with attachments")); chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new LabeledIntent[intents.size()])); startActivity(chooser); } else { System.out.println("email:" + "No Email App found"); new AlertDialog.Builder(c).setMessage(Navit.get_text("No Email App found")) .setPositiveButton(Navit.get_text("Ok"), null).show(); } // final Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", recipient, null)); // if (recipient != null) emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { recipient }); // if (subject != null) emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); // if (message != null) emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); // if (full_file_name != null) // { // emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + full_file_name)); // //ArrayList<Uri> uris = new ArrayList<>(); // //uris.add(Uri.parse("file://" + full_file_name)); // //emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); //ArrayList<Uri> of attachment Uri's // } // // List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(emailIntent, 0); // if (resolveInfos.size() != 0) // { // String packageName = resolveInfos.get(0).activityInfo.packageName; // String name = resolveInfos.get(0).activityInfo.name; // // emailIntent.setAction(Intent.ACTION_SEND); // emailIntent.setComponent(new ComponentName(packageName, name)); // // System.out.println("email:" + "comp=" + packageName + " " + name); // // startActivity(emailIntent); // } // else // { // System.out.println("email:" + "No Email App found"); // new AlertDialog.Builder(c).setMessage(Navit.get_text("No Email App found")).setPositiveButton(Navit.get_text("Ok"), null).show(); // } } catch (ActivityNotFoundException e) { // cannot send email for some reason } }