Example usage for android.content Intent ACTION_SEND_MULTIPLE

List of usage examples for android.content Intent ACTION_SEND_MULTIPLE

Introduction

In this page you can find the example usage for android.content Intent ACTION_SEND_MULTIPLE.

Prototype

String ACTION_SEND_MULTIPLE

To view the source code for android.content Intent ACTION_SEND_MULTIPLE.

Click Source Link

Document

Activity Action: Deliver multiple data to someone else.

Usage

From source file:com.ubuntuone.android.files.activity.FilesActivity.java

private void onOptionShareSelected() {
    String node = mPathTracker.getCurrentNode();
    String uploadResourcePath = (node == null) ? Preferences.U1_RESOURCE : node;

    String action = shareIntent != null ? shareIntent.getAction() : null;
    if (Intent.ACTION_SEND.equals(action)) {
        onSendAction(shareIntent, uploadResourcePath);
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        onSendMultipleAction(shareIntent, uploadResourcePath);
    }//from   w  ww.j  a v a2 s .co m
    shareIntent = null;
    mIsPickShareWithDirectoryMode = false;
    finish();
}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

private boolean handleDefaultIntent(final Intent intent) {
    if (intent == null)
        return false;
    final String action = intent.getAction();
    final boolean hasAccountIds;
    if (intent.hasExtra(EXTRA_ACCOUNT_IDS)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongArrayExtra(EXTRA_ACCOUNT_IDS));
        hasAccountIds = true;/*from   ww  w .  ja va 2 s . co  m*/
    } else if (intent.hasExtra(EXTRA_ACCOUNT_ID)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongExtra(EXTRA_ACCOUNT_ID, -1));
        hasAccountIds = true;
    } else {
        hasAccountIds = false;
    }
    mShouldSaveAccounts = !Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action)
            && !hasAccountIds;
    final Uri data = intent.getData();
    final CharSequence extraSubject = intent.getCharSequenceExtra(Intent.EXTRA_SUBJECT);
    final CharSequence extraText = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
    final Uri extraStream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
    //TODO handle share_screenshot extra (Bitmap)
    if (extraStream != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, extraStream, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (data != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, data, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (intent.hasExtra(EXTRA_SHARE_SCREENSHOT) && Utils.useShareScreenshot()) {
        final Bitmap bitmap = intent.getParcelableExtra(EXTRA_SHARE_SCREENSHOT);
        if (bitmap != null) {
            try {
                AsyncTaskUtils.executeTask(
                        new AddBitmapTask(this, bitmap, createTempImageUri(), ParcelableMedia.TYPE_IMAGE));
            } catch (IOException e) {
                // ignore
                bitmap.recycle();
            }
        }
    }
    mEditText.setText(getShareStatus(this, extraSubject, extraText));
    final int selection_end = mEditText.length();
    mEditText.setSelection(selection_end);
    return true;
}

From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java

private boolean handleDefaultIntent(final Intent intent) {
    if (intent == null)
        return false;
    final String action = intent.getAction();
    final boolean hasAccountIds;
    if (intent.hasExtra(EXTRA_ACCOUNT_IDS)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongArrayExtra(EXTRA_ACCOUNT_IDS));
        hasAccountIds = true;/*w  w w . ja  va2 s  .c om*/
    } else if (intent.hasExtra(EXTRA_ACCOUNT_ID)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongExtra(EXTRA_ACCOUNT_ID, -1));
        hasAccountIds = true;
    } else {
        hasAccountIds = false;
    }
    mShouldSaveAccounts = !Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action)
            && !hasAccountIds;
    final Uri data = intent.getData();
    final CharSequence extraSubject = intent.getCharSequenceExtra(Intent.EXTRA_SUBJECT);
    final CharSequence extraText = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
    final Uri extraStream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
    //TODO handle share_screenshot extra (Bitmap)
    if (extraStream != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, extraStream, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (data != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, data, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (intent.hasExtra(EXTRA_SHARE_SCREENSHOT) && Utils.useShareScreenshot()) {
        final Bitmap bitmap = intent.getParcelableExtra(EXTRA_SHARE_SCREENSHOT);
        if (bitmap != null) {
            try {
                AsyncTaskUtils.executeTask(
                        new AddBitmapTask(this, bitmap, createTempImageUri(), ParcelableMedia.TYPE_IMAGE));
            } catch (IOException e) {
                // ignore
                bitmap.recycle();
            }
        }
    }
    mEditText.setText(Utils.getShareStatus(this, extraSubject, extraText));
    final int selectionEnd = mEditText.length();
    mEditText.setSelection(selectionEnd);
    return true;
}

From source file:ac.robinson.mediaphone.MediaPhoneActivity.java

private void sendFiles(final ArrayList<Uri> filesToSend) {
    // send files in a separate task without a dialog so we don't leave the previous progress dialog behind on
    // screen rotation - this is a bit of a hack, but it works
    runImmediateBackgroundTask(new BackgroundRunnable() {
        @Override/*from   w  w w.j  a  va  2  s  . c  o m*/
        public int getTaskId() {
            return 0;
        }

        @Override
        public boolean getShowDialog() {
            return false;
        }

        @Override
        public void run() {
            if (filesToSend == null || filesToSend.size() <= 0) {
                return;
            }

            // ensure files are accessible to send - bit of a last-ditch effort for when temp is on internal storage
            for (Uri fileUri : filesToSend) {
                IOUtilities.setFullyPublic(new File(fileUri.getPath()));
            }

            // also see: http://stackoverflow.com/questions/2344768/
            // could use application/smil+xml (or html), or video/quicktime, but then there's no bluetooth option
            final Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
            sendIntent.setType(getString(R.string.export_mime_type));
            sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, filesToSend);

            final Intent chooserIntent = Intent.createChooser(sendIntent,
                    getString(R.string.export_narrative_title));

            // an extra activity at the start of the list that moves exported files to SD, but only if SD available
            if (IOUtilities.externalStorageIsWritable()) {
                final Intent targetedShareIntent = new Intent(MediaPhoneActivity.this,
                        SaveNarrativeActivity.class);
                targetedShareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                targetedShareIntent.setType(getString(R.string.export_mime_type));
                targetedShareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, filesToSend);
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[] { targetedShareIntent });
            }

            startActivity(chooserIntent); // single task mode; no return value given
        }
    });
}

From source file:org.cafemember.ui.LaunchActivity.java

private boolean handleIntent(Intent intent, boolean isNew, boolean restore, boolean fromPassword) {
    int flags = intent.getFlags();
    if (!fromPassword && (AndroidUtilities.needShowPasscode(true) || UserConfig.isWaitingForPasscodeEnter)) {
        showPasscodeActivity();// w w  w.  j a  v a2 s . c  om
        passcodeSaveIntent = intent;
        passcodeSaveIntentIsNew = isNew;
        passcodeSaveIntentIsRestore = restore;
        UserConfig.saveConfig(false);
    } else {
        boolean pushOpened = false;

        Integer push_user_id = 0;
        Integer push_chat_id = 0;
        Integer push_enc_id = 0;
        Integer open_settings = 0;
        long dialogId = intent != null && intent.getExtras() != null ? intent.getExtras().getLong("dialogId", 0)
                : 0;
        boolean showDialogsList = false;
        boolean showPlayer = false;

        photoPathsArray = null;
        videoPath = null;
        sendingText = null;
        documentsPathsArray = null;
        documentsOriginalPathsArray = null;
        documentsMimeType = null;
        documentsUrisArray = null;
        contactsToSend = null;

        if (UserConfig.isClientActivated() && (flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
            if (intent != null && intent.getAction() != null && !restore) {
                if (Intent.ACTION_SEND.equals(intent.getAction())) {
                    boolean error = false;
                    String type = intent.getType();
                    if (type != null && type.equals(ContactsContract.Contacts.CONTENT_VCARD_TYPE)) {
                        try {
                            Uri uri = (Uri) intent.getExtras().get(Intent.EXTRA_STREAM);
                            if (uri != null) {
                                ContentResolver cr = getContentResolver();
                                InputStream stream = cr.openInputStream(uri);

                                String name = null;
                                String nameEncoding = null;
                                String nameCharset = null;
                                ArrayList<String> phones = new ArrayList<>();
                                BufferedReader bufferedReader = new BufferedReader(
                                        new InputStreamReader(stream, "UTF-8"));
                                String line;
                                while ((line = bufferedReader.readLine()) != null) {
                                    String[] args = line.split(":");
                                    if (args.length != 2) {
                                        continue;
                                    }
                                    if (args[0].startsWith("FN")) {
                                        String[] params = args[0].split(";");
                                        for (String param : params) {
                                            String[] args2 = param.split("=");
                                            if (args2.length != 2) {
                                                continue;
                                            }
                                            if (args2[0].equals("CHARSET")) {
                                                nameCharset = args2[1];
                                            } else if (args2[0].equals("ENCODING")) {
                                                nameEncoding = args2[1];
                                            }
                                        }
                                        name = args[1];
                                        if (nameEncoding != null
                                                && nameEncoding.equalsIgnoreCase("QUOTED-PRINTABLE")) {
                                            while (name.endsWith("=") && nameEncoding != null) {
                                                name = name.substring(0, name.length() - 1);
                                                line = bufferedReader.readLine();
                                                if (line == null) {
                                                    break;
                                                }
                                                name += line;
                                            }
                                            byte[] bytes = AndroidUtilities
                                                    .decodeQuotedPrintable(name.getBytes());
                                            if (bytes != null && bytes.length != 0) {
                                                String decodedName = new String(bytes, nameCharset);
                                                if (decodedName != null) {
                                                    name = decodedName;
                                                }
                                            }
                                        }
                                    } else if (args[0].startsWith("TEL")) {
                                        String phone = PhoneFormat.stripExceptNumbers(args[1], true);
                                        if (phone.length() > 0) {
                                            phones.add(phone);
                                        }
                                    }
                                }
                                try {
                                    bufferedReader.close();
                                    stream.close();
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                if (name != null && !phones.isEmpty()) {
                                    contactsToSend = new ArrayList<>();
                                    for (String phone : phones) {
                                        TLRPC.User user = new TLRPC.TL_userContact_old2();
                                        user.phone = phone;
                                        user.first_name = name;
                                        user.last_name = "";
                                        user.id = 0;
                                        contactsToSend.add(user);
                                    }
                                }
                            } else {
                                error = true;
                            }
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                            error = true;
                        }
                    } else {
                        String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                        if (text == null) {
                            CharSequence textSequence = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
                            if (textSequence != null) {
                                text = textSequence.toString();
                            }
                        }
                        String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);

                        if (text != null && text.length() != 0) {
                            if ((text.startsWith("http://") || text.startsWith("https://")) && subject != null
                                    && subject.length() != 0) {
                                text = subject + "\n" + text;
                            }
                            sendingText = text;
                        } else if (subject != null && subject.length() > 0) {
                            sendingText = subject;
                        }

                        Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
                        if (parcelable != null) {
                            String path;
                            if (!(parcelable instanceof Uri)) {
                                parcelable = Uri.parse(parcelable.toString());
                            }
                            Uri uri = (Uri) parcelable;
                            if (uri != null) {
                                if (isInternalUri(uri)) {
                                    error = true;
                                }
                            }
                            if (!error) {
                                if (uri != null && (type != null && type.startsWith("image/")
                                        || uri.toString().toLowerCase().endsWith(".jpg"))) {
                                    if (photoPathsArray == null) {
                                        photoPathsArray = new ArrayList<>();
                                    }
                                    photoPathsArray.add(uri);
                                } else {
                                    path = AndroidUtilities.getPath(uri);
                                    if (path != null) {
                                        if (path.startsWith("file:")) {
                                            path = path.replace("file://", "");
                                        }
                                        if (type != null && type.startsWith("video/")) {
                                            videoPath = path;
                                        } else {
                                            if (documentsPathsArray == null) {
                                                documentsPathsArray = new ArrayList<>();
                                                documentsOriginalPathsArray = new ArrayList<>();
                                            }
                                            documentsPathsArray.add(path);
                                            documentsOriginalPathsArray.add(uri.toString());
                                        }
                                    } else {
                                        if (documentsUrisArray == null) {
                                            documentsUrisArray = new ArrayList<>();
                                        }
                                        documentsUrisArray.add(uri);
                                        documentsMimeType = type;
                                    }
                                }
                                if (sendingText != null) {
                                    if (sendingText.contains("WhatsApp")) { //remove unnecessary caption 'sent from WhatsApp' from photos forwarded from WhatsApp
                                        sendingText = null;
                                    }
                                }
                            }
                        } else if (sendingText == null) {
                            error = true;
                        }
                    }
                    if (error) {
                        Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
                    }
                } else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
                    boolean error = false;
                    try {
                        ArrayList<Parcelable> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                        String type = intent.getType();
                        if (uris != null) {
                            for (int a = 0; a < uris.size(); a++) {
                                Parcelable parcelable = uris.get(a);
                                if (!(parcelable instanceof Uri)) {
                                    parcelable = Uri.parse(parcelable.toString());
                                }
                                Uri uri = (Uri) parcelable;
                                if (uri != null) {
                                    if (isInternalUri(uri)) {
                                        uris.remove(a);
                                        a--;
                                    }
                                }
                            }
                            if (uris.isEmpty()) {
                                uris = null;
                            }
                        }
                        if (uris != null) {
                            if (type != null && type.startsWith("image/")) {
                                for (int a = 0; a < uris.size(); a++) {
                                    Parcelable parcelable = uris.get(a);
                                    if (!(parcelable instanceof Uri)) {
                                        parcelable = Uri.parse(parcelable.toString());
                                    }
                                    Uri uri = (Uri) parcelable;
                                    if (photoPathsArray == null) {
                                        photoPathsArray = new ArrayList<>();
                                    }
                                    photoPathsArray.add(uri);
                                }
                            } else {
                                for (int a = 0; a < uris.size(); a++) {
                                    Parcelable parcelable = uris.get(a);
                                    if (!(parcelable instanceof Uri)) {
                                        parcelable = Uri.parse(parcelable.toString());
                                    }
                                    String path = AndroidUtilities.getPath((Uri) parcelable);
                                    String originalPath = parcelable.toString();
                                    if (originalPath == null) {
                                        originalPath = path;
                                    }
                                    if (path != null) {
                                        if (path.startsWith("file:")) {
                                            path = path.replace("file://", "");
                                        }
                                        if (documentsPathsArray == null) {
                                            documentsPathsArray = new ArrayList<>();
                                            documentsOriginalPathsArray = new ArrayList<>();
                                        }
                                        documentsPathsArray.add(path);
                                        documentsOriginalPathsArray.add(originalPath);
                                    }
                                }
                            }
                        } else {
                            error = true;
                        }
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                        error = true;
                    }
                    if (error) {
                        Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show();
                    }
                } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
                    Uri data = intent.getData();
                    if (data != null) {
                        String username = null;
                        String group = null;
                        String sticker = null;
                        String botUser = null;
                        String botChat = null;
                        String message = null;
                        Integer messageId = null;
                        boolean hasUrl = false;
                        String scheme = data.getScheme();
                        if (scheme != null) {
                            if ((scheme.equals("http") || scheme.equals("https"))) {
                                String host = data.getHost().toLowerCase();
                                if (host.equals("telegram.me") || host.equals("telegram.dog")) {
                                    String path = data.getPath();
                                    if (path != null && path.length() > 1) {
                                        path = path.substring(1);
                                        if (path.startsWith("joinchat/")) {
                                            group = path.replace("joinchat/", "");
                                        } else if (path.startsWith("addstickers/")) {
                                            sticker = path.replace("addstickers/", "");
                                        } else if (path.startsWith("msg/") || path.startsWith("share/")) {
                                            message = data.getQueryParameter("url");
                                            if (message == null) {
                                                message = "";
                                            }
                                            if (data.getQueryParameter("text") != null) {
                                                if (message.length() > 0) {
                                                    hasUrl = true;
                                                    message += "\n";
                                                }
                                                message += data.getQueryParameter("text");
                                            }
                                        } else if (path.length() >= 1) {
                                            List<String> segments = data.getPathSegments();
                                            if (segments.size() > 0) {
                                                username = segments.get(0);
                                                if (segments.size() > 1) {
                                                    messageId = Utilities.parseInt(segments.get(1));
                                                    if (messageId == 0) {
                                                        messageId = null;
                                                    }
                                                }
                                            }
                                            botUser = data.getQueryParameter("start");
                                            botChat = data.getQueryParameter("startgroup");
                                        }
                                    }
                                }
                            } else if (scheme.equals("tg")) {
                                String url = data.toString();
                                if (url.startsWith("tg:resolve") || url.startsWith("tg://resolve")) {
                                    url = url.replace("tg:resolve", "tg://telegram.org").replace("tg://resolve",
                                            "tg://telegram.org");
                                    data = Uri.parse(url);
                                    username = data.getQueryParameter("domain");
                                    botUser = data.getQueryParameter("start");
                                    botChat = data.getQueryParameter("startgroup");
                                } else if (url.startsWith("tg:join") || url.startsWith("tg://join")) {
                                    url = url.replace("tg:join", "tg://telegram.org").replace("tg://join",
                                            "tg://telegram.org");
                                    data = Uri.parse(url);
                                    group = data.getQueryParameter("invite");
                                } else if (url.startsWith("tg:addstickers")
                                        || url.startsWith("tg://addstickers")) {
                                    url = url.replace("tg:addstickers", "tg://telegram.org")
                                            .replace("tg://addstickers", "tg://telegram.org");
                                    data = Uri.parse(url);
                                    sticker = data.getQueryParameter("set");
                                } else if (url.startsWith("tg:msg") || url.startsWith("tg://msg")
                                        || url.startsWith("tg://share") || url.startsWith("tg:share")) {
                                    url = url.replace("tg:msg", "tg://telegram.org")
                                            .replace("tg://msg", "tg://telegram.org")
                                            .replace("tg://share", "tg://telegram.org")
                                            .replace("tg:share", "tg://telegram.org");
                                    data = Uri.parse(url);
                                    message = data.getQueryParameter("url");
                                    if (message == null) {
                                        message = "";
                                    }
                                    if (data.getQueryParameter("text") != null) {
                                        if (message.length() > 0) {
                                            hasUrl = true;
                                            message += "\n";
                                        }
                                        message += data.getQueryParameter("text");
                                    }
                                }
                            }
                        }
                        if (username != null || group != null || sticker != null || message != null) {
                            runLinkRequest(username, group, sticker, botUser, botChat, message, hasUrl,
                                    messageId, 0);
                        } else {
                            try {
                                Cursor cursor = getContentResolver().query(intent.getData(), null, null, null,
                                        null);
                                if (cursor != null) {
                                    if (cursor.moveToFirst()) {
                                        int userId = cursor.getInt(cursor.getColumnIndex("DATA4"));
                                        NotificationCenter.getInstance()
                                                .postNotificationName(NotificationCenter.closeChats);
                                        push_user_id = userId;
                                    }
                                    cursor.close();
                                }
                            } catch (Exception e) {
                                FileLog.e("tmessages", e);
                            }
                        }
                    }
                } else if (intent.getAction().equals("org.telegram.messenger.OPEN_ACCOUNT")) {
                    open_settings = 1;
                } else if (intent.getAction().startsWith("com.tmessages.openchat")) {
                    int chatId = intent.getIntExtra("chatId", 0);
                    int userId = intent.getIntExtra("userId", 0);
                    int encId = intent.getIntExtra("encId", 0);
                    if (chatId != 0) {
                        NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
                        push_chat_id = chatId;
                    } else if (userId != 0) {
                        NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
                        push_user_id = userId;
                    } else if (encId != 0) {
                        NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
                        push_enc_id = encId;
                    } else {
                        showDialogsList = true;
                    }
                } else if (intent.getAction().equals("com.tmessages.openplayer")) {
                    showPlayer = true;
                }
            }
        }

        if (push_user_id != 0) {
            Bundle args = new Bundle();
            args.putInt("user_id", push_user_id);
            if (mainFragmentsStack.isEmpty() || MessagesController.checkCanOpenChat(args,
                    mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
                ChatActivity fragment = new ChatActivity(args);
                if (actionBarLayout.presentFragment(fragment, false, true, true)) {
                    pushOpened = true;
                }
            }
        } else if (push_chat_id != 0) {
            Bundle args = new Bundle();
            args.putInt("chat_id", push_chat_id);
            if (mainFragmentsStack.isEmpty() || MessagesController.checkCanOpenChat(args,
                    mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
                ChatActivity fragment = new ChatActivity(args);
                if (actionBarLayout.presentFragment(fragment, false, true, true)) {
                    pushOpened = true;
                }
            }
        } else if (push_enc_id != 0) {
            Bundle args = new Bundle();
            args.putInt("enc_id", push_enc_id);
            ChatActivity fragment = new ChatActivity(args);
            if (actionBarLayout.presentFragment(fragment, false, true, true)) {
                pushOpened = true;
            }
        } else if (showDialogsList) {
            if (!AndroidUtilities.isTablet()) {
                actionBarLayout.removeAllFragments();
            } else {
                if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
                    for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
                        layersActionBarLayout
                                .removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
                        a--;
                    }
                    layersActionBarLayout.closeLastFragment(false);
                }
            }
            pushOpened = false;
            isNew = false;
        } else if (showPlayer) {
            if (AndroidUtilities.isTablet()) {
                for (int a = 0; a < layersActionBarLayout.fragmentsStack.size(); a++) {
                    BaseFragment fragment = layersActionBarLayout.fragmentsStack.get(a);
                    if (fragment instanceof AudioPlayerActivity) {
                        layersActionBarLayout.removeFragmentFromStack(fragment);
                        break;
                    }
                }
                actionBarLayout.showLastFragment();
                rightActionBarLayout.showLastFragment();
                drawerLayoutContainer.setAllowOpenDrawer(false, false);
            } else {
                for (int a = 0; a < actionBarLayout.fragmentsStack.size(); a++) {
                    BaseFragment fragment = actionBarLayout.fragmentsStack.get(a);
                    if (fragment instanceof AudioPlayerActivity) {
                        actionBarLayout.removeFragmentFromStack(fragment);
                        break;
                    }
                }
                drawerLayoutContainer.setAllowOpenDrawer(true, false);
            }
            actionBarLayout.presentFragment(new AudioPlayerActivity(), false, true, true);
            pushOpened = true;
        } else if (videoPath != null || photoPathsArray != null || sendingText != null
                || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) {
            if (!AndroidUtilities.isTablet()) {
                NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
            }
            if (dialogId == 0) {
                Bundle args = new Bundle();
                args.putBoolean("onlySelect", true);
                if (contactsToSend != null) {
                    args.putString("selectAlertString",
                            LocaleController.getString("SendContactTo", R.string.SendMessagesTo));
                    args.putString("selectAlertStringGroup",
                            LocaleController.getString("SendContactToGroup", R.string.SendContactToGroup));
                } else {
                    args.putString("selectAlertString",
                            LocaleController.getString("SendMessagesTo", R.string.SendMessagesTo));
                    args.putString("selectAlertStringGroup",
                            LocaleController.getString("SendMessagesToGroup", R.string.SendMessagesToGroup));
                }
                DialogsActivity fragment = new DialogsActivity(args);
                dialogsFragment = fragment;
                fragment.setDelegate(this);
                boolean removeLast;
                if (AndroidUtilities.isTablet()) {
                    removeLast = layersActionBarLayout.fragmentsStack.size() > 0
                            && layersActionBarLayout.fragmentsStack.get(
                                    layersActionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
                } else {
                    removeLast = actionBarLayout.fragmentsStack.size() > 1 && actionBarLayout.fragmentsStack
                            .get(actionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
                }
                actionBarLayout.presentFragment(fragment, removeLast, true, true);
                pushOpened = true;
                if (PhotoViewer.getInstance().isVisible()) {
                    PhotoViewer.getInstance().closePhoto(false, true);
                }

                drawerLayoutContainer.setAllowOpenDrawer(false, false);
                if (AndroidUtilities.isTablet()) {
                    actionBarLayout.showLastFragment();
                    rightActionBarLayout.showLastFragment();
                } else {
                    drawerLayoutContainer.setAllowOpenDrawer(true, false);
                }
            } else {
                didSelectDialog(null, dialogId, false);
            }
        } else if (open_settings != 0) {
            actionBarLayout.presentFragment(new SettingsActivity(), false, true, true);
            if (AndroidUtilities.isTablet()) {
                actionBarLayout.showLastFragment();
                rightActionBarLayout.showLastFragment();
                drawerLayoutContainer.setAllowOpenDrawer(false, false);
            } else {
                drawerLayoutContainer.setAllowOpenDrawer(true, false);
            }
            pushOpened = true;
        }

        if (!pushOpened && !isNew) {
            if (AndroidUtilities.isTablet()) {
                if (!UserConfig.isClientActivated()) {
                    if (layersActionBarLayout.fragmentsStack.isEmpty()) {
                        layersActionBarLayout.addFragmentToStack(new LoginActivity());
                        drawerLayoutContainer.setAllowOpenDrawer(false, false);
                    }
                } else {
                    if (actionBarLayout.fragmentsStack.isEmpty()) {
                        actionBarLayout.addFragmentToStack(new DialogsActivity(null));
                        drawerLayoutContainer.setAllowOpenDrawer(true, false);
                    }
                }
            } else {
                if (actionBarLayout.fragmentsStack.isEmpty()) {
                    if (!UserConfig.isClientActivated()) {
                        actionBarLayout.addFragmentToStack(new LoginActivity());
                        drawerLayoutContainer.setAllowOpenDrawer(false, false);
                    } else {
                        actionBarLayout.addFragmentToStack(new DialogsActivity(null));
                        drawerLayoutContainer.setAllowOpenDrawer(true, false);
                    }
                }
            }
            actionBarLayout.showLastFragment();
            if (AndroidUtilities.isTablet()) {
                layersActionBarLayout.showLastFragment();
                rightActionBarLayout.showLastFragment();
            }
        }

        intent.setAction(null);
        return pushOpened;
    }
    return false;
}

From source file:com.crearo.gpslogger.GpsMainActivity.java

/**
 * Allows user to send a GPX/KML file along with location, or location only
 * using a provider. 'Provider' means any application that can accept such
 * an intent (Facebook, SMS, Twitter, Email, K-9, Bluetooth)
 *//*from  w  ww .  j  av a 2  s .co  m*/
private void share() {

    try {

        final String locationOnly = getString(R.string.sharing_location_only);
        final File gpxFolder = new File(preferenceHelper.getGpsLoggerFolder());
        if (gpxFolder.exists()) {

            File[] enumeratedFiles = Files.fromFolder(gpxFolder);

            Arrays.sort(enumeratedFiles, new Comparator<File>() {
                public int compare(File f1, File f2) {
                    return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
                }
            });

            List<String> fileList = new ArrayList<>(enumeratedFiles.length);

            for (File f : enumeratedFiles) {
                fileList.add(f.getName());
            }

            fileList.add(0, locationOnly);
            final String[] files = fileList.toArray(new String[fileList.size()]);

            new MaterialDialog.Builder(this).title(R.string.osm_pick_file).items(files)
                    .positiveText(R.string.ok)
                    .itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMultiChoice() {
                        @Override
                        public boolean onSelection(MaterialDialog materialDialog, Integer[] integers,
                                CharSequence[] charSequences) {
                            List<Integer> selectedItems = Arrays.asList(integers);

                            final Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType("*/*");

                            if (selectedItems.size() <= 0) {
                                return false;
                            }

                            if (selectedItems.contains(0)) {

                                intent.setType("text/plain");

                                intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation));
                                if (Session.hasValidLocation()) {
                                    String bodyText = getString(R.string.sharing_googlemaps_link,
                                            String.valueOf(Session.getCurrentLatitude()),
                                            String.valueOf(Session.getCurrentLongitude()));
                                    intent.putExtra(Intent.EXTRA_TEXT, bodyText);
                                    intent.putExtra("sms_body", bodyText);
                                    startActivity(
                                            Intent.createChooser(intent, getString(R.string.sharing_via)));
                                }
                            } else {

                                intent.setAction(Intent.ACTION_SEND_MULTIPLE);
                                intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
                                intent.setType("*/*");

                                ArrayList<Uri> chosenFiles = new ArrayList<>();

                                for (Object path : selectedItems) {
                                    File file = new File(gpxFolder, files[Integer.valueOf(path.toString())]);
                                    Uri uri = Uri.fromFile(file);
                                    chosenFiles.add(uri);
                                }

                                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFiles);
                                startActivity(Intent.createChooser(intent, getString(R.string.sharing_via)));
                            }
                            return true;
                        }
                    }).show();

        } else {
            Dialogs.alert(getString(R.string.sorry), getString(R.string.no_files_found), this);
        }
    } catch (Exception ex) {
        LOG.error("Sharing problem", ex);
    }
}

From source file:org.planetmono.dcuploader.ActivityUploader.java

@SuppressWarnings("unchecked")
@Override//w  ww .j av  a2 s . c  o  m
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    initViews();
    if (formLocation)
        queryLocation(true);

    if (savedState != null) {
        if (savedState.containsKey("tempfile"))
            tempFile = new File(savedState.getString("tempfile"));
        if (savedState.containsKey("target"))
            resolveTarget(savedState.getString("target"));
        if (savedState.containsKey("tempfiles"))
            tempFiles = savedState.getStringArrayList("tempfiles");
        if (savedState.containsKey("contents")) {
            contents = new ArrayList<Uri>();
            String[] carr = savedState.getStringArray("contents");
            for (String s : carr)
                contents.add(Uri.parse(s));
        }
    }

    postfix = "from <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>";

    Button uploadVisit = (Button) findViewById(R.id.upload_visit);
    if (passThrough || target == null)
        uploadVisit.setEnabled(false);
    else
        uploadVisit.setEnabled(true);

    /* populate data by getting STREAM parameter */
    Intent i = getIntent();
    Bundle b = i.getExtras();
    String action = i.getAction();

    if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) {
        called = true;

        if (i.hasExtra(Intent.EXTRA_STREAM)) {
            Object o = b.get(Intent.EXTRA_STREAM);

            /* quick and dirty. any better idea? */
            try {
                contents.add((Uri) o);
            } catch (Exception e1) {
                try {
                    contents = (ArrayList<Uri>) ((ArrayList<Uri>) o).clone();
                } catch (Exception e2) {
                }
            }

            boolean exceeded = false;
            if (contents.size() > 5) {
                exceeded = true;

                do {
                    contents.remove(5);
                } while (contents.size() > 5);
            }

            galleryChanged = true;

            updateImageButtons();
            resetThumbnails();
            updateGallery();

            if (exceeded)
                Toast.makeText(this,
                        " 5  . 5 ??? ? ?.",
                        Toast.LENGTH_LONG).show();
        }
        if (i.hasExtra(Intent.EXTRA_TEXT)) {
            ((EditText) findViewById(R.id.upload_text)).setText(b.getString(Intent.EXTRA_TEXT));
        }
    } else if (action.equals("share")) {
        called = true;
        /* HTC web browser uses non-standard intent */

        ((EditText) findViewById(R.id.upload_text)).setText(b.getString(Intent.EXTRA_TITLE));
    } else if (action.equals(Intent.ACTION_VIEW)) {
        Uri uri = i.getData();

        if (i.getCategories().contains(Intent.CATEGORY_BROWSABLE)) {
            passThrough = true;

            Pattern p = Pattern.compile("id=([\\-a-zA-Z0-9_]+)");
            Matcher m = p.matcher(uri.toString());

            if (m.find()) {
                resolveTarget(m.group(1));
            } else {
                passThrough = false;
            }

            if (uri.getHost().equals(Application.HOST_DCMYS)) {
                destination = Application.DESTINATION_DCMYS;
                postfix = "from dc.m.dcmys.kr w/ <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>";
            } else if (uri.getHost().equals(Application.HOST_MOOLZO)) {
                destination = Application.DESTINATION_MOOLZO;
                postfix = "- From m.oolzo.com w/ <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>";
            } else if (uri.getHost().equals(Application.HOST_DCINSIDE)) {
                destination = Application.DESTINATION_DCINSIDE;
            }

            setDefaultImage();
        }
    }

    reloadConfigurations();
}

From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java

private boolean setComposeTitle(final Intent intent) {
    final String action = intent.getAction();
    if (INTENT_ACTION_REPLY.equals(action)) {
        if (mInReplyToStatus == null)
            return false;
        final String display_name = getDisplayName(this, mInReplyToStatus.user_id, mInReplyToStatus.user_name,
                mInReplyToStatus.user_screen_name);
        setTitle(getString(R.string.reply_to, display_name));
    } else if (INTENT_ACTION_QUOTE.equals(action)) {
        if (mInReplyToStatus == null)
            return false;
        final String display_name = getDisplayName(this, mInReplyToStatus.user_id, mInReplyToStatus.user_name,
                mInReplyToStatus.user_screen_name);
        setTitle(getString(R.string.quote_user, display_name));
        mSubtitleView.setVisibility(//from w w w .j ava2s .c om
                mInReplyToStatus.user_is_protected && mInReplyToStatus.account_id != mInReplyToStatus.user_id
                        ? View.VISIBLE
                        : View.GONE);
    } else if (INTENT_ACTION_EDIT_DRAFT.equals(action)) {
        if (mDraftItem == null)
            return false;
        setTitle(R.string.edit_draft);
    } else if (INTENT_ACTION_MENTION.equals(action)) {
        if (mMentionUser == null)
            return false;
        final String display_name = getDisplayName(this, mMentionUser.id, mMentionUser.name,
                mMentionUser.screen_name);
        setTitle(getString(R.string.mention_user, display_name));
    } else if (INTENT_ACTION_REPLY_MULTIPLE.equals(action)) {
        setTitle(R.string.reply);
    } else if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        setTitle(R.string.share);
    } else {
        setTitle(R.string.compose);
    }
    return true;
}

From source file:com.intel.xdk.device.Device.java

public void sendEmail(String body, String to, String subject, boolean ishtml, String cc, String bcc) {

    String toArray[] = to.split(",");
    String ccArray[] = cc.split(",");
    String bccArray[] = bcc.split(",");

    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); // it's not ACTION_SEND
    if (ishtml) {
        //Android default mail clients poorly support html formatted mail :(
        //intent.setType("text/html");
        //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body,null,null));
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, body);
    } else {// w  w w .  j a  v a2s  . c  o m
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, body);
    }

    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    if (toArray.length > 0 && !toArray[0].equals("")) {
        intent.putExtra(Intent.EXTRA_EMAIL, toArray);
    }
    if (ccArray.length > 0 && !ccArray[0].equals("")) {
        intent.putExtra(Intent.EXTRA_CC, ccArray);
    }
    if (bccArray.length > 0 && !bccArray[0].equals("")) {
        intent.putExtra(Intent.EXTRA_BCC, bccArray);
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //return user to app after sending mail
    activity.startActivity(intent);
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

private boolean handleSendToAction() {
    Intent intent = getIntent();//from ww w  .j  a  va  2  s .c  o  m
    String action = intent.getAction();
    long filesize = 0;

    if (action != null) {
        if (action.equals(Intent.ACTION_SEND_MULTIPLE)) {

            showErrorExit(R.string.error_MultipleSendNotSupported);
            return false;

        } else if (action.equals(Intent.ACTION_SEND)) {
            DraftData d = DraftData.INSTANCE;

            d.setMsgHash(null);

            String type = intent.getType();
            Uri stream = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
            CharSequence extra_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);

            // if this is from a share menu
            try {
                // Get resource path from intent caller
                if (Intent.ACTION_SEND.equals(action)) {
                    if (stream != null) {
                        filesize = getOutStreamSizeAndData(stream, type);
                    } else if (!TextUtils.isEmpty(extra_text)) {
                        filesize = extra_text.length();
                        if (filesize <= SafeSlingerConfig.MAX_TEXTMESSAGE) {
                            d.removeFile();
                            d.setText(extra_text.toString());
                        } else {
                            d.setFileType("text/plain");
                            final byte[] textBytes = extra_text.toString().getBytes();
                            d.setFileData(textBytes);
                            d.setFileSize(textBytes.length);
                            SimpleDateFormat sdf = new SimpleDateFormat(SafeSlingerConfig.DATETIME_FILENAME,
                                    Locale.US);
                            d.setFileName(sdf.format(new Date()) + ".txt");
                            d.removeText();
                        }
                    }
                }

                if (filesize <= 0) {
                    showErrorExit(R.string.error_CannotSendEmptyFile);
                    return false;
                }
                if (filesize > SafeSlingerConfig.MAX_FILEBYTES) {
                    showErrorExit(String.format(getString(R.string.error_CannotSendFilesOver),
                            SafeSlingerConfig.MAX_FILEBYTES));
                    return false;
                }
            } catch (IOException e) {
                showErrorExit(e);
                return false;
            } catch (OutOfMemoryError e) {
                showErrorExit(R.string.error_OutOfMemoryError);
                return false;
            }
        }
    }
    return true;
}