Example usage for android.content Intent getType

List of usage examples for android.content Intent getType

Introduction

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

Prototype

public @Nullable String getType() 

Source Link

Document

Retrieve any explicit MIME type included in the intent.

Usage

From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java

private void share() {
    GalleryItemViewTag tag = getCurrentTag();
    if (tag == null)
        return;/* ww  w .  j a  va 2s  . c o  m*/
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    String extension = Attachments.getAttachmentExtention(tag.attachmentModel);
    switch (tag.attachmentModel.type) {
    case AttachmentModel.TYPE_IMAGE_GIF:
        shareIntent.setType("image/gif");
        break;
    case AttachmentModel.TYPE_IMAGE_SVG:
        shareIntent.setType("image/svg+xml");
        break;
    case AttachmentModel.TYPE_IMAGE_STATIC:
        if (extension.equalsIgnoreCase(".png")) {
            shareIntent.setType("image/png");
        } else if (extension.equalsIgnoreCase(".jpg") || extension.equalsIgnoreCase(".jpg")) {
            shareIntent.setType("image/jpeg");
        } else {
            shareIntent.setType("image/*");
        }
        break;
    case AttachmentModel.TYPE_VIDEO:
        if (extension.equalsIgnoreCase(".mp4")) {
            shareIntent.setType("video/mp4");
        } else if (extension.equalsIgnoreCase(".webm")) {
            shareIntent.setType("video/webm");
        } else if (extension.equalsIgnoreCase(".avi")) {
            shareIntent.setType("video/avi");
        } else if (extension.equalsIgnoreCase(".mov")) {
            shareIntent.setType("video/quicktime");
        } else if (extension.equalsIgnoreCase(".mkv")) {
            shareIntent.setType("video/x-matroska");
        } else if (extension.equalsIgnoreCase(".flv")) {
            shareIntent.setType("video/x-flv");
        } else if (extension.equalsIgnoreCase(".wmv")) {
            shareIntent.setType("video/x-ms-wmv");
        } else {
            shareIntent.setType("video/*");
        }
        break;
    case AttachmentModel.TYPE_AUDIO:
        if (extension.equalsIgnoreCase(".mp3")) {
            shareIntent.setType("audio/mpeg");
        } else if (extension.equalsIgnoreCase(".mp4")) {
            shareIntent.setType("audio/mp4");
        } else if (extension.equalsIgnoreCase(".ogg")) {
            shareIntent.setType("audio/ogg");
        } else if (extension.equalsIgnoreCase(".webm")) {
            shareIntent.setType("audio/webm");
        } else if (extension.equalsIgnoreCase(".flac")) {
            shareIntent.setType("audio/flac");
        } else if (extension.equalsIgnoreCase(".wav")) {
            shareIntent.setType("audio/vnd.wave");
        } else {
            shareIntent.setType("audio/*");
        }
        break;
    case AttachmentModel.TYPE_OTHER_FILE:
        shareIntent.setType("application/octet-stream");
        break;
    }
    Logger.d(TAG, shareIntent.getType());
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tag.file));
    startActivity(Intent.createChooser(shareIntent, getString(R.string.share_via)));
}

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

private boolean handleSendToAction() {
    Intent intent = getIntent();
    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);//from  w  w w. jav a 2 s . c  o  m

            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;
}

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 ava 2 s .  c  o  m
        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:edu.mit.viral.shen.DroidFish.java

private final Pair<String, String> getPgnOrFenIntent() {
    String pgnOrFen = null;/* w w w  .j  a va  2 s.co m*/
    String filename = null;
    try {
        Intent intent = getIntent();
        Uri data = intent.getData();
        if (data == null) {
            if ((Intent.ACTION_SEND.equals(intent.getAction()) || Intent.ACTION_VIEW.equals(intent.getAction()))
                    && ("application/x-chess-pgn".equals(intent.getType())
                            || "application/x-chess-fen".equals(intent.getType())))
                pgnOrFen = intent.getStringExtra(Intent.EXTRA_TEXT);
        } else {
            String scheme = intent.getScheme();
            if ("file".equals(scheme)) {
                filename = data.getEncodedPath();
                if (filename != null)
                    filename = Uri.decode(filename);
            }
            if ((filename == null) && ("content".equals(scheme) || "file".equals(scheme))) {
                ContentResolver resolver = getContentResolver();
                InputStream in = resolver.openInputStream(intent.getData());
                StringBuilder sb = new StringBuilder();
                while (true) {
                    byte[] buffer = new byte[16384];
                    int len = in.read(buffer);
                    if (len <= 0)
                        break;
                    sb.append(new String(buffer, 0, len));
                }
                pgnOrFen = sb.toString();
            }
        }
    } catch (IOException e) {
        Toast.makeText(getApplicationContext(), R.string.failed_to_read_pgn_data, Toast.LENGTH_SHORT).show();
    }
    return new Pair<String, String>(pgnOrFen, filename);
}

From source file:org.mdc.chess.MDChess.java

/**
 * Return PGN/FEN data or filename from the Intent. Both can not be non-null.
 *
 * @return Pair of PGN/FEN data and filename.
 *//*from w  w  w.j a v  a 2 s.c  o  m*/
private Pair<String, String> getPgnOrFenIntent() {
    String pgnOrFen = null;
    String filename = null;
    try {
        Intent intent = getIntent();
        Uri data = intent.getData();
        if (data == null) {
            Bundle b = intent.getExtras();
            if (b != null) {
                Object strm = b.get(Intent.EXTRA_STREAM);
                if (strm instanceof Uri) {
                    data = (Uri) strm;
                    if ("file".equals(data.getScheme())) {
                        filename = data.getEncodedPath();
                        if (filename != null) {
                            filename = Uri.decode(filename);
                        }
                    }
                }
            }
        }
        if (data == null) {
            if ((Intent.ACTION_SEND.equals(intent.getAction()) || Intent.ACTION_VIEW.equals(intent.getAction()))
                    && ("application/x-chess-pgn".equals(intent.getType())
                            || "application/x-chess-fen".equals(intent.getType()))) {
                pgnOrFen = intent.getStringExtra(Intent.EXTRA_TEXT);
            }
        } else {
            String scheme = intent.getScheme();
            if ("file".equals(scheme)) {
                filename = data.getEncodedPath();
                if (filename != null) {
                    filename = Uri.decode(filename);
                }
            }
            if ((filename == null) && ("content".equals(scheme) || "file".equals(scheme))) {
                ContentResolver resolver = getContentResolver();
                InputStream in = resolver.openInputStream(intent.getData());
                StringBuilder sb = new StringBuilder();
                while (true) {
                    byte[] buffer = new byte[16384];
                    int len = in != null ? in.read(buffer) : 0;
                    if (len <= 0) {
                        break;
                    }
                    sb.append(new String(buffer, 0, len));
                }
                pgnOrFen = sb.toString();
            }
        }
    } catch (IOException e) {
        Toast.makeText(getApplicationContext(), R.string.failed_to_read_pgn_data, Toast.LENGTH_SHORT).show();
    }
    return new Pair<>(pgnOrFen, filename);
}

From source file:org.kontalk.ui.ComposeMessageFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // image from storage/picture from camera
    // since there are like up to 3 different ways of doing this...
    if (requestCode == SELECT_ATTACHMENT_OPENABLE || requestCode == SELECT_ATTACHMENT_PHOTO) {
        if (resultCode == Activity.RESULT_OK) {
            Uri[] uris = null;/*  ww  w.  j  av  a  2  s. c  o m*/
            String[] mimes = null;

            // returning from camera
            if (data == null) {
                if (mCurrentPhoto != null) {
                    Uri uri = Uri.fromFile(mCurrentPhoto);
                    // notify media scanner
                    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                    mediaScanIntent.setData(uri);
                    getActivity().sendBroadcast(mediaScanIntent);
                    mCurrentPhoto = null;

                    uris = new Uri[] { uri };
                }
            } else {
                if (mCurrentPhoto != null) {
                    mCurrentPhoto.delete();
                    mCurrentPhoto = null;
                }

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && data.getClipData() != null) {
                    ClipData cdata = data.getClipData();
                    uris = new Uri[cdata.getItemCount()];

                    for (int i = 0; i < uris.length; i++) {
                        ClipData.Item item = cdata.getItemAt(i);
                        uris[i] = item.getUri();
                    }
                } else {
                    uris = new Uri[] { data.getData() };
                    mimes = new String[] { data.getType() };
                }

                // SAF available, request persistable permissions
                if (MediaStorage.isStorageAccessFrameworkAvailable()) {
                    for (Uri uri : uris) {
                        if (uri != null && !"file".equals(uri.getScheme())) {
                            MediaStorage.requestPersistablePermissions(getActivity(), uri);
                        }
                    }
                }
            }

            for (int i = 0; uris != null && i < uris.length; i++) {
                Uri uri = uris[i];
                String mime = (mimes != null && mimes.length >= uris.length) ? mimes[i] : null;

                if (mime == null || mime.startsWith("*/") || mime.endsWith("/*")) {
                    mime = MediaStorage.getType(getActivity(), uri);
                    Log.v(TAG, "using detected mime type " + mime);
                }

                if (ImageComponent.supportsMimeType(mime))
                    sendBinaryMessage(uri, mime, true, ImageComponent.class);
                else if (VCardComponent.supportsMimeType(mime))
                    sendBinaryMessage(uri, VCardComponent.MIME_TYPE, false, VCardComponent.class);
                else
                    Toast.makeText(getActivity(), R.string.send_mime_not_supported, Toast.LENGTH_LONG).show();
            }
        }
        // operation aborted
        else {
            // delete photo :)
            if (mCurrentPhoto != null) {
                mCurrentPhoto.delete();
                mCurrentPhoto = null;
            }
        }
    }
    // contact card (vCard)
    else if (requestCode == SELECT_ATTACHMENT_CONTACT) {
        if (resultCode == Activity.RESULT_OK) {
            Uri uri = data.getData();
            if (uri != null) {
                // get lookup key
                final Cursor c = getActivity().getContentResolver().query(uri,
                        new String[] { Contacts.LOOKUP_KEY }, null, null, null);
                if (c != null) {
                    try {
                        c.moveToFirst();
                        String lookupKey = c.getString(0);
                        Uri vcardUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
                        sendBinaryMessage(vcardUri, VCardComponent.MIME_TYPE, false, VCardComponent.class);
                    } finally {
                        c.close();
                    }
                }
            }
        }
    }
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

private boolean handleSendIntent() {
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();/*from  www .  j a  va  2 s  . c o m*/
    if (extras == null) {
        return false;
    }

    final String mimeType = intent.getType();
    String action = intent.getAction();
    if (Intent.ACTION_SEND.equals(action)) {
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            final Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            getAsyncDialog().runAsync(new Runnable() {
                @Override
                public void run() {
                    addAttachment(mimeType, uri, false);
                }
            }, null, R.string.adding_attachments_title);
            return true;
        } else if (extras.containsKey(Intent.EXTRA_TEXT)) {
            mWorkingMessage.setText(extras.getString(Intent.EXTRA_TEXT));
            return true;
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && extras.containsKey(Intent.EXTRA_STREAM)) {
        SlideshowModel slideShow = mWorkingMessage.getSlideshow();
        final ArrayList<Parcelable> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
        int currentSlideCount = slideShow != null ? slideShow.size() : 0;
        int importCount = uris.size();
        if (importCount + currentSlideCount > SlideshowEditor.MAX_SLIDE_NUM) {
            importCount = Math.min(SlideshowEditor.MAX_SLIDE_NUM - currentSlideCount, importCount);
            Toast.makeText(ComposeMessageActivity.this,
                    getString(R.string.too_many_attachments, SlideshowEditor.MAX_SLIDE_NUM, importCount),
                    Toast.LENGTH_LONG).show();
        }

        // Attach all the pictures/videos asynchronously off of the UI thread.
        // Show a progress dialog if adding all the slides hasn't finished
        // within half a second.
        final int numberToImport = importCount;
        getAsyncDialog().runAsync(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < numberToImport; i++) {
                    Parcelable uri = uris.get(i);
                    addAttachment(mimeType, (Uri) uri, true);
                }
            }
        }, null, R.string.adding_attachments_title);
        return true;
    }
    return false;
}

From source file:it.feio.android.omninotes.DetailFragment.java

private void handleIntents() {
    Intent i = mainActivity.getIntent();

    if (IntentChecker.checkAction(i, Constants.ACTION_MERGE)) {
        noteOriginal = new Note();
        note = new Note(noteOriginal);
        noteTmp = getArguments().getParcelable(Constants.INTENT_NOTE);
        if (i.getStringArrayListExtra("merged_notes") != null) {
            mergedNotesIds = i.getStringArrayListExtra("merged_notes");
        }/*from   w ww  . java 2s  . c  o m*/
    }

    // Action called from home shortcut
    if (IntentChecker.checkAction(i, Constants.ACTION_SHORTCUT, Constants.ACTION_NOTIFICATION_CLICK)) {
        afterSavedReturnsToList = false;
        noteOriginal = DbHelper.getInstance().getNote(i.getLongExtra(Constants.INTENT_KEY, 0));
        // Checks if the note pointed from the shortcut has been deleted
        try {
            note = new Note(noteOriginal);
            noteTmp = new Note(noteOriginal);
        } catch (NullPointerException e) {
            mainActivity.showToast(getText(R.string.shortcut_note_deleted), Toast.LENGTH_LONG);
            mainActivity.finish();
        }
    }

    // Check if is launched from a widget
    if (IntentChecker.checkAction(i, Constants.ACTION_WIDGET, Constants.ACTION_TAKE_PHOTO)) {

        afterSavedReturnsToList = false;
        showKeyboard = true;

        //  with tags to set tag
        if (i.hasExtra(Constants.INTENT_WIDGET)) {
            String widgetId = i.getExtras().get(Constants.INTENT_WIDGET).toString();
            if (widgetId != null) {
                String sqlCondition = prefs.getString(Constants.PREF_WIDGET_PREFIX + widgetId, "");
                String categoryId = TextHelper.checkIntentCategory(sqlCondition);
                if (categoryId != null) {
                    Category category;
                    try {
                        category = DbHelper.getInstance().getCategory(Long.parseLong(categoryId));
                        noteTmp = new Note();
                        noteTmp.setCategory(category);
                    } catch (NumberFormatException e) {
                        Log.e(Constants.TAG, "Category with not-numeric value!", e);
                    }
                }
            }
        }

        // Sub-action is to take a photo
        if (IntentChecker.checkAction(i, Constants.ACTION_TAKE_PHOTO)) {
            takePhoto();
        }
    }

    /**
     * Handles third party apps requests of sharing
     */
    if (IntentChecker.checkAction(i, Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE,
            Constants.INTENT_GOOGLE_NOW) && i.getType() != null) {

        afterSavedReturnsToList = false;

        if (noteTmp == null)
            noteTmp = new Note();

        // Text title
        String title = i.getStringExtra(Intent.EXTRA_SUBJECT);
        if (title != null) {
            noteTmp.setTitle(title);
        }

        // Text content
        String content = i.getStringExtra(Intent.EXTRA_TEXT);
        if (content != null) {
            noteTmp.setContent(content);
        }

        // Single attachment data
        Uri uri = i.getParcelableExtra(Intent.EXTRA_STREAM);
        // Due to the fact that Google Now passes intent as text but with
        // audio recording attached the case must be handled in specific way
        if (uri != null && !Constants.INTENT_GOOGLE_NOW.equals(i.getAction())) {
            String name = FileHelper.getNameFromUri(mainActivity, uri);
            AttachmentTask task = new AttachmentTask(this, uri, name, this);
            task.execute();
        }

        // Multiple attachment data
        ArrayList<Uri> uris = i.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (uris != null) {
            for (Uri uriSingle : uris) {
                String name = FileHelper.getNameFromUri(mainActivity, uriSingle);
                AttachmentTask task = new AttachmentTask(this, uriSingle, name, this);
                task.execute();
            }
        }

        //         i.setAction(null);
    }

    if (IntentChecker.checkAction(i, Intent.ACTION_MAIN, Constants.ACTION_WIDGET_SHOW_LIST)) {
        showKeyboard = true;
    }

}

From source file:com.dycody.android.idealnote.DetailFragment.java

private void handleIntents() {
    Intent i = mainActivity.getIntent();

    if (IntentChecker.checkAction(i, Constants.ACTION_MERGE)) {
        noteOriginal = new Note();
        note = new Note(noteOriginal);
        noteTmp = getArguments().getParcelable(Constants.INTENT_NOTE);
        if (i.getStringArrayListExtra("merged_notes") != null) {
            mergedNotesIds = i.getStringArrayListExtra("merged_notes");
        }//  ww  w.  j a v a  2s.  c  om
    }

    // Action called from home shortcut
    if (IntentChecker.checkAction(i, Constants.ACTION_SHORTCUT, Constants.ACTION_NOTIFICATION_CLICK)) {
        afterSavedReturnsToList = false;
        noteOriginal = DbHelper.getInstance().getNote(i.getLongExtra(Constants.INTENT_KEY, 0));
        // Checks if the note pointed from the shortcut has been deleted
        try {
            note = new Note(noteOriginal);
            noteTmp = new Note(noteOriginal);
        } catch (NullPointerException e) {
            mainActivity.showToast(getText(R.string.shortcut_note_deleted), Toast.LENGTH_LONG);
            mainActivity.finish();
        }
    }

    // Check if is launched from a widget
    if (IntentChecker.checkAction(i, Constants.ACTION_WIDGET, Constants.ACTION_TAKE_PHOTO)) {

        afterSavedReturnsToList = false;
        showKeyboard = true;

        //  with tags to set tag
        if (i.hasExtra(Constants.INTENT_WIDGET)) {
            String widgetId = i.getExtras().get(Constants.INTENT_WIDGET).toString();
            if (widgetId != null) {
                String sqlCondition = prefs.getString(Constants.PREF_WIDGET_PREFIX + widgetId, "");
                String categoryId = TextHelper.checkIntentCategory(sqlCondition);
                if (categoryId != null) {
                    Category category;
                    try {
                        category = DbHelper.getInstance().getCategory(Long.parseLong(categoryId));
                        noteTmp = new Note();
                        noteTmp.setCategory(category);
                    } catch (NumberFormatException e) {
                        Log.e(Constants.TAG, "Category with not-numeric value!", e);
                    }
                }
            }
        }

        // Sub-action is to take a photo
        if (IntentChecker.checkAction(i, Constants.ACTION_TAKE_PHOTO)) {
            takePhoto();
        }
    }

    /**
     * Handles third party apps requests of sharing
     */
    if (IntentChecker.checkAction(i, Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE,
            Constants.INTENT_GOOGLE_NOW) && i.getType() != null) {

        afterSavedReturnsToList = false;

        if (noteTmp == null)
            noteTmp = new Note();

        // Text title
        String title = i.getStringExtra(Intent.EXTRA_SUBJECT);
        if (title != null) {
            noteTmp.setTitle(title);
        }

        // Text content
        String content = i.getStringExtra(Intent.EXTRA_TEXT);
        if (content != null) {
            noteTmp.setContent(content);
        }

        // Single attachment data
        Uri uri = i.getParcelableExtra(Intent.EXTRA_STREAM);
        // Due to the fact that Google Now passes intent as text but with
        // audio recording attached the case must be handled in specific way
        if (uri != null && !Constants.INTENT_GOOGLE_NOW.equals(i.getAction())) {
            String name = FileHelper.getNameFromUri(mainActivity, uri);
            new AttachmentTask(this, uri, name, this).execute();
        }

        // Multiple attachment data
        ArrayList<Uri> uris = i.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (uris != null) {
            for (Uri uriSingle : uris) {
                String name = FileHelper.getNameFromUri(mainActivity, uriSingle);
                new AttachmentTask(this, uriSingle, name, this).execute();
            }
        }
    }

    if (IntentChecker.checkAction(i, Intent.ACTION_MAIN, Constants.ACTION_WIDGET_SHOW_LIST,
            Constants.ACTION_SHORTCUT_WIDGET, Constants.ACTION_WIDGET)) {
        showKeyboard = true;
    }

    i.setAction(null);
}

From source file:com.github.dfa.diaspora_android.activity.ShareActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override/* w  ww . j a  v  a 2s.  c om*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main__activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (toolbar != null) {
        toolbar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Helpers.isOnline(ShareActivity.this)) {
                    Intent intent = new Intent(ShareActivity.this, MainActivity.class);
                    startActivityForResult(intent, 100);
                    overridePendingTransition(0, 0);
                    finish();
                } else {
                    Snackbar.make(swipeView, R.string.no_internet, Snackbar.LENGTH_LONG).show();
                }
            }
        });
    }
    setTitle(R.string.new_post);

    progressBar = (ProgressBar) findViewById(R.id.progressBar);

    swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe);
    swipeView.setEnabled(false);

    podDomain = ((App) getApplication()).getSettings().getPodDomain();

    webView = (WebView) findViewById(R.id.webView);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

    WebSettings wSettings = webView.getSettings();
    wSettings.setJavaScriptEnabled(true);
    wSettings.setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT >= 21)
        wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

    /*
     * WebViewClient
     */
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.d(TAG, url);
            if (!url.contains(podDomain)) {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(i);
                return true;
            }
            return false;

        }

        public void onPageFinished(WebView view, String url) {
            Log.i(TAG, "Finished loading URL: " + url);
        }
    });

    /*
     * WebChromeClient
     */
    webView.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView wv, int progress) {
            progressBar.setProgress(progress);

            if (progress > 0 && progress <= 60) {
                Helpers.getNotificationCount(wv);
            }

            if (progress > 60) {
                Helpers.applyDiasporaMobileSiteChanges(wv);
            }

            if (progress == 100) {
                progressBar.setVisibility(View.GONE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                FileChooserParams fileChooserParams) {
            if (mFilePathCallback != null)
                mFilePathCallback.onReceiveValue(null);

            mFilePathCallback = filePathCallback;

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                // Create the File where the photo should go
                File photoFile = null;
                try {
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                } catch (IOException ex) {
                    // Error occurred while creating the File
                    Snackbar.make(getWindow().findViewById(R.id.main__layout), "Unable to get image",
                            Snackbar.LENGTH_LONG).show();
                }

                // Continue only if the File was successfully created
                if (photoFile != null) {
                    mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                } else {
                    takePictureIntent = null;
                }
            }

            Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("image/*");

            Intent[] intentArray;
            if (takePictureIntent != null) {
                intentArray = new Intent[] { takePictureIntent };
            } else {
                intentArray = new Intent[0];
            }

            Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
            chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
            chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

            startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

            return true;
        }
    });

    if (savedInstanceState == null) {
        if (Helpers.isOnline(ShareActivity.this)) {
            webView.loadUrl("https://" + podDomain + "/status_messages/new");
        } else {
            Snackbar.make(getWindow().findViewById(R.id.main__layout), R.string.no_internet,
                    Snackbar.LENGTH_LONG).show();
        }
    }

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {
                handleSendSubject(intent);
            } else {
                handleSendText(intent);
            }
        } else if (type.startsWith("image/")) {
            // TODO Handle single image being sent -> see manifest
            handleSendImage(intent);
        }
        //} else {
        // Handle other intents, such as being started from the home screen
    }

}