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:android.support.v7.widget.ShareActionProvider.java

/**
 * Sets an intent with information about the share action. Here is a
 * sample for constructing a share intent:
 * <p>/*from w  w w  .  j a  va  2  s. co  m*/
 * <pre>
 * <code>
 *  Intent shareIntent = new Intent(Intent.ACTION_SEND);
 *  shareIntent.setType("image/*");
 *  Uri uri = Uri.fromFile(new File(getFilesDir(), "foo.jpg"));
 *  shareIntent.putExtra(Intent.EXTRA_STREAM, uri.toString());
 * </pre>
 * </code>
 * </p>
 *
 * @param shareIntent The share intent.
 *
 * @see Intent#ACTION_SEND
 * @see Intent#ACTION_SEND_MULTIPLE
 */
public void setShareIntent(Intent shareIntent) {
    if (shareIntent != null) {
        final String action = shareIntent.getAction();
        if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
            updateIntent(shareIntent);
        }
    }
    ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
    dataModel.setIntent(shareIntent);
}

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

private boolean receivedIntent(Intent i) {
    return Constants.ACTION_SHORTCUT.equals(i.getAction())
            || Constants.ACTION_NOTIFICATION_CLICK.equals(i.getAction())
            || Constants.ACTION_WIDGET.equals(i.getAction())
            || Constants.ACTION_TAKE_PHOTO.equals(i.getAction())
            || ((Intent.ACTION_SEND.equals(i.getAction()) || Intent.ACTION_SEND_MULTIPLE.equals(i.getAction())
                    || Constants.INTENT_GOOGLE_NOW.equals(i.getAction())) && i.getType() != null)
            || i.getAction().contains(Constants.ACTION_NOTIFICATION_CLICK);
}

From source file:com.nexes.manager.EventHandler.java

/**
 * This method, handles the button presses of the top buttons found in the
 * Main activity.// w  w w  .  ja v  a 2  s.  c om
 */
@Override
public void onClick(View v) {

    switch (v.getId()) {

    case R.id.back_button:
        if (mFileMang.getCurrentDir() != "/") {
            if (multi_select_flag) {
                mDelegate.killMultiSelect(true);
                Toast.makeText(mContext, "Multi-select is now off", Toast.LENGTH_SHORT).show();
            }

            stopThumbnailThread();
            updateDirectory(mFileMang.getPreviousDir());
            if (mPathLabel != null)
                mPathLabel.setText(mFileMang.getCurrentDir());
        }
        break;

    case R.id.home_button:
        if (multi_select_flag) {
            mDelegate.killMultiSelect(true);
            Toast.makeText(mContext, "Multi-select is now off", Toast.LENGTH_SHORT).show();
        }

        stopThumbnailThread();
        updateDirectory(mFileMang.setHomeDir("/sdcard"));
        if (mPathLabel != null)
            mPathLabel.setText(mFileMang.getCurrentDir());
        break;

    case R.id.info_button:
        Intent info = new Intent(mContext, DirectoryInfo.class);
        info.putExtra("PATH_NAME", mFileMang.getCurrentDir());
        mContext.startActivity(info);
        break;

    case R.id.help_button:
        Intent help = new Intent(mContext, HelpManager.class);
        mContext.startActivity(help);
        break;

    case R.id.manage_button:
        display_dialog(MANAGE_DIALOG);
        break;

    case R.id.multiselect_button:
        if (multi_select_flag) {
            mDelegate.killMultiSelect(true);

        } else {
            LinearLayout hidden_lay = (LinearLayout) ((Activity) mContext).findViewById(R.id.hidden_buttons);

            multi_select_flag = true;
            hidden_lay.setVisibility(LinearLayout.VISIBLE);
        }
        break;

    /*
     * three hidden buttons for multiselect
     */
    case R.id.hidden_attach:
        /* check if user selected objects before going further */
        if (mMultiSelectData == null || mMultiSelectData.isEmpty()) {
            mDelegate.killMultiSelect(true);
            break;
        }

        ArrayList<Uri> uris = new ArrayList<Uri>();
        int length = mMultiSelectData.size();
        Intent mail_int = new Intent();

        mail_int.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
        mail_int.setType("application/mail");
        mail_int.putExtra(Intent.EXTRA_BCC, "");
        mail_int.putExtra(Intent.EXTRA_SUBJECT, " ");

        for (int i = 0; i < length; i++) {
            File file = new File(mMultiSelectData.get(i));
            uris.add(Uri.fromFile(file));
        }

        mail_int.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        mContext.startActivity(Intent.createChooser(mail_int, "Email using..."));

        mDelegate.killMultiSelect(true);
        break;

    case R.id.hidden_move:
    case R.id.hidden_copy:
        /* check if user selected objects before going further */
        if (mMultiSelectData == null || mMultiSelectData.isEmpty()) {
            mDelegate.killMultiSelect(true);
            break;
        }

        if (v.getId() == R.id.hidden_move)
            delete_after_copy = true;

        mInfoLabel.setText("Holding " + mMultiSelectData.size() + " file(s)");

        mDelegate.killMultiSelect(false);
        break;

    case R.id.hidden_delete:
        /* check if user selected objects before going further */
        if (mMultiSelectData == null || mMultiSelectData.isEmpty()) {
            mDelegate.killMultiSelect(true);
            break;
        }

        final String[] data = new String[mMultiSelectData.size()];
        int at = 0;

        for (String string : mMultiSelectData)
            data[at++] = string;

        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(
                "Are you sure you want to delete " + data.length + " files? This cannot be " + "undone.");
        builder.setCancelable(false);
        builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                new BackgroundWork(DELETE_TYPE).execute(data);
                mDelegate.killMultiSelect(true);
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mDelegate.killMultiSelect(true);
                dialog.cancel();
            }
        });

        builder.create().show();
        break;
    }
}

From source file:com.swisscom.safeconnect.activity.DashboardActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_show_log:
        Intent logIntent = new Intent(this, LogActivity.class);
        startActivity(logIntent);//from   w w w.j  a v a  2  s. c  o m
        return true;
    case R.id.menu_send_log:
        File log = Logger.saveLogs(this);
        File charonlog = new File(getFilesDir(), CharonVpnService.LOG_FILE);

        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "manuel.cianci1@swisscom.com" });
        intent.putExtra(Intent.EXTRA_SUBJECT, "PipeOfTrust LogFiles");
        intent.setType("text/plain");

        ArrayList<Uri> files = new ArrayList<Uri>();
        if (charonlog.exists() && charonlog.length() > 0) {
            files.add(LogContentProvider.createContentUri());
        }
        if (log.exists() && log.length() > 0) {
            files.add(Uri.fromFile(log));
        }
        if (files.size() == 0) {
            Toast.makeText(this, "Log is empty!", Toast.LENGTH_SHORT).show();
            return true;
        }

        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
        startActivity(Intent.createChooser(intent, getString(R.string.send_log)));
        return true;
    case R.id.menu_change_num:
        if (mService.getState() == VpnStateService.State.CONNECTED) {
            mService.disconnect();
        }
        intent = new Intent(this, RegistrationActivity.class);
        intent.putExtra(RegistrationActivity.FORCE_ACTIVITY, true);
        startActivity(intent);
        finish();
        return true;
    case R.id.menu_help:
        startActivity(new Intent(this, FaqActivity.class));
        return true;
    case R.id.menu_settings:
        Intent settingsIntent = new Intent(this, SettingsActivity.class);
        startActivity(settingsIntent);
        return true;
    case R.id.menu_share:
        share();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:org.alfresco.mobile.android.application.manager.ActionManager.java

public static void actionSendDocumentsToAlfresco(Fragment fr, List<File> files) {
    if (files.size() == 1) {
        actionSendDocumentToAlfresco(fr.getActivity(), files.get(0));
        return;//from   ww  w  .ja  v a 2s. com
    }

    try {
        Intent i = new Intent(fr.getActivity(), PublicDispatcherActivity.class);
        i.setAction(Intent.ACTION_SEND_MULTIPLE);
        ArrayList<Uri> uris = new ArrayList<Uri>();
        // convert from paths to Android friendly Parcelable Uri's
        for (File file : files) {
            Uri u = Uri.fromFile(file);
            uris.add(u);
        }
        i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        i.setType(MimeTypeManager.getMIMEType(fr.getActivity(), "text/plain"));
        fr.getActivity().startActivity(i);
    } catch (ActivityNotFoundException e) {
        MessengerManager.showToast(fr.getActivity(), R.string.error_unable_share_content);
    }
}

From source file:org.matrix.console.activity.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (CommonActivityUtils.shouldRestartApp()) {
        Log.e(LOG_TAG, "Restart the application.");
        CommonActivityUtils.restartApp(this);
    }//from w  ww  .j  a  v  a  2 s  .co  m

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    mMyRoomList = (ExpandableListView) findViewById(R.id.listView_myRooms);
    // the chevron is managed in the header view
    mMyRoomList.setGroupIndicator(null);
    mAdapter = new ConsoleRoomSummaryAdapter(this, Matrix.getMXSessions(this), R.layout.adapter_item_my_rooms,
            R.layout.adapter_room_section_header);

    if (null != savedInstanceState) {
        if (savedInstanceState.containsKey(PUBLIC_ROOMS_LIST_LIST)) {
            Serializable map = savedInstanceState.getSerializable(PUBLIC_ROOMS_LIST_LIST);

            if (null != map) {
                HashMap<String, List<PublicRoom>> hash = (HashMap<String, List<PublicRoom>>) map;
                mPublicRoomsListList = new ArrayList<List<PublicRoom>>(hash.values());
                mHomeServerNames = new ArrayList<>(hash.keySet());
            }
        }
    }

    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_JUMP_TO_ROOM_ID)) {
        mAutomaticallyOpenedRoomId = intent.getStringExtra(EXTRA_JUMP_TO_ROOM_ID);
    }

    if (intent.hasExtra(EXTRA_JUMP_MATRIX_ID)) {
        mAutomaticallyOpenedMatrixId = intent.getStringExtra(EXTRA_JUMP_MATRIX_ID);
    }

    if (intent.hasExtra(EXTRA_ROOM_INTENT)) {
        mOpenedRoomIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT);
    }

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

    // send files from external application
    if ((Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) && type != null) {
        this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                CommonActivityUtils.sendFilesTo(HomeActivity.this, intent);
            }
        });
    }

    mMyRoomList.setAdapter(mAdapter);
    Collection<MXSession> sessions = Matrix.getMXSessions(HomeActivity.this);

    // check if  there is some valid session
    // the home activity could be relaunched after an application crash
    // so, reload the sessions before displaying the hidtory
    if (sessions.size() == 0) {
        Log.e(LOG_TAG, "Weird : onCreate : no session");

        if (null != Matrix.getInstance(this).getDefaultSession()) {
            Log.e(LOG_TAG, "No loaded session : reload them");
            startActivity(new Intent(HomeActivity.this, SplashActivity.class));
            HomeActivity.this.finish();
            return;
        }
    }

    for (MXSession session : sessions) {
        addSessionListener(session);
    }

    mMyRoomList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {

            if (mAdapter.isRecentsGroupIndex(groupPosition)) {
                String roomId = null;
                MXSession session = null;

                RoomSummary roomSummary = mAdapter.getRoomSummaryAt(groupPosition, childPosition);
                session = Matrix.getInstance(HomeActivity.this).getSession(roomSummary.getMatrixId());

                roomId = roomSummary.getRoomId();
                Room room = session.getDataHandler().getRoom(roomId);
                // cannot join a leaving room
                if ((null == room) || room.isLeaving()) {
                    roomId = null;
                }

                if (mAdapter.resetUnreadCount(groupPosition, roomId)) {
                    session.getDataHandler().getStore().flushSummary(roomSummary);
                }

                if (null != roomId) {
                    CommonActivityUtils.goToRoomPage(session, roomId, HomeActivity.this, null);
                }

            } else if (mAdapter.isPublicsGroupIndex(groupPosition)) {
                joinPublicRoom(mAdapter.getHomeServerURLAt(groupPosition),
                        mAdapter.getPublicRoomAt(groupPosition, childPosition));
            }

            return true;
        }
    });

    mMyRoomList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                long packedPos = ((ExpandableListView) parent).getExpandableListPosition(position);
                final int groupPosition = ExpandableListView.getPackedPositionGroup(packedPos);

                if (mAdapter.isRecentsGroupIndex(groupPosition)) {
                    final int childPosition = ExpandableListView.getPackedPositionChild(packedPos);

                    FragmentManager fm = HomeActivity.this.getSupportFragmentManager();
                    IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm
                            .findFragmentByTag(TAG_FRAGMENT_ROOM_OPTIONS);

                    if (fragment != null) {
                        fragment.dismissAllowingStateLoss();
                    }

                    final Integer[] lIcons = new Integer[] { R.drawable.ic_material_exit_to_app };
                    final Integer[] lTexts = new Integer[] { R.string.action_leave };

                    fragment = IconAndTextDialogFragment.newInstance(lIcons, lTexts);
                    fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() {
                        @Override
                        public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) {
                            Integer selectedVal = lTexts[position];

                            if (selectedVal == R.string.action_leave) {
                                HomeActivity.this.runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        final RoomSummary roomSummary = mAdapter.getRoomSummaryAt(groupPosition,
                                                childPosition);
                                        final MXSession session = Matrix.getInstance(HomeActivity.this)
                                                .getSession(roomSummary.getMatrixId());

                                        String roomId = roomSummary.getRoomId();
                                        Room room = session.getDataHandler().getRoom(roomId);

                                        if (null != room) {
                                            room.leave(new SimpleApiCallback<Void>(HomeActivity.this) {
                                                @Override
                                                public void onSuccess(Void info) {
                                                    mAdapter.removeRoomSummary(groupPosition, roomSummary);
                                                    mAdapter.notifyDataSetChanged();
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });

                    fragment.show(fm, TAG_FRAGMENT_ROOM_OPTIONS);

                    return true;
                }
            }

            return false;
        }
    });

    mMyRoomList.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
        @Override
        public void onGroupExpand(int groupPosition) {
            if (mAdapter.isPublicsGroupIndex(groupPosition)) {
                refreshPublicRoomsList();
            }
        }
    });

    mMyRoomList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            return mAdapter.getGroupCount() < 2;
        }
    });

    mSearchRoomEditText = (EditText) this.findViewById(R.id.editText_search_room);
    mSearchRoomEditText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(android.text.Editable s) {
            mAdapter.setSearchedPattern(s.toString());
            mMyRoomList.smoothScrollToPosition(0);
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
}

From source file:de.enlightened.peris.PerisMain.java

/**
 * Called when the activity is first created.
 *//*from w  w w .ja v  a  2 s .c om*/
@SuppressLint("NewApi")
@Override
public final void onCreate(final Bundle savedInstanceState) {
    this.application = (PerisApp) getApplication();
    this.application.setActive(true);
    this.backStackId = this.application.getBackStackId();
    this.ah = this.application.getAnalyticsHelper();

    if (this.application.getSession().getServer().serverIcon == null) {
        final int optimalIconSize = (int) this.getResources().getDimension(android.R.dimen.app_icon_size);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
            new CheckForumIconTask(this.application.getSession(), optimalIconSize)
                    .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else {
            new CheckForumIconTask(this.application.getSession(), optimalIconSize).execute();
        }
    }
    this.serverAddress = this.application.getSession().getServer().serverAddress;
    final SharedPreferences appPreferences = getSharedPreferences("prefs", 0);
    this.sidebarOption = appPreferences.getBoolean("show_sidebar", true);
    this.screenTitle = getString(R.string.app_name);

    if (getString(R.string.server_location).contentEquals("0")) {
        this.storagePrefix = this.serverAddress + "_";
        this.screenSubtitle = this.serverAddress;
    } else {
        this.screenSubtitle = this.screenTitle;
    }
    this.serverUserid = this.application.getSession().getServer().serverUserId;
    final String tagline = this.application.getSession().getServer().serverTagline;
    final SharedPreferences.Editor editor = appPreferences.edit();

    if (tagline.contentEquals("null") || tagline.contentEquals("0")) {
        final String deviceName = android.os.Build.MODEL;
        final String appName = getString(R.string.app_name);
        final String appVersion = getString(R.string.app_version);
        String appColor = getString(R.string.default_color);

        if (this.application.getSession().getServer().serverColor.contains("#")) {
            appColor = this.application.getSession().getServer().serverColor;
        }
        final String standardTagline = "[color=" + appColor + "][b]Sent from my " + deviceName + " using "
                + appName + " v" + appVersion + ".[/b][/color]";
        this.application.getSession().getServer().serverTagline = standardTagline;
        this.application.getSession().updateServer();
    }
    editor.putInt(this.storagePrefix + "just_logged_in", 0);
    editor.commit();

    if (this.serverUserid != null) {
        final Toast toast = Toast.makeText(PerisMain.this,
                "TIP: Tap on the key icon to log in to your forum account.", Toast.LENGTH_LONG);
        toast.show();
    }
    final Intent intent = getIntent();
    final String action = intent.getAction();
    final String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            this.handleSendText(intent); // Handle text being sent
        } else if (type.startsWith("image/")) {
            this.handleSendImage(intent); // Handle single image being sent
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            this.handleSendMultipleImages(intent); // Handle multiple images being sent
        }
    } /*else {
      // Handle other intents, such as being started from the home screen
      }*/

    this.background = this.application.getSession().getServer().serverColor;
    ThemeSetter.setTheme(this, this.background);
    super.onCreate(savedInstanceState);
    ThemeSetter.setActionBar(this, this.background);
    this.actionBar = getActionBar();
    this.actionBar.setDisplayHomeAsUpEnabled(true);
    this.actionBar.setHomeButtonEnabled(true);
    this.actionBar.setTitle(this.screenTitle);
    this.actionBar.setSubtitle(this.screenSubtitle);

    //Send app analytics data
    this.ah.trackScreen(getClass().getSimpleName(), false);
    this.ah.trackEvent("server connection", "connected", "connected", false);

    //Send tracking data for parsed analytics from peris.json
    this.serverAddress = this.application.getSession().getServer().analyticsId;
    if (this.serverAddress != null) {
        this.ah.trackCustomScreen(this.serverAddress,
                "Peris Forum Reader v" + getString(R.string.app_version) + " for Android");
    }
    setContentView(R.layout.main_swipe);

    this.mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    this.flSecondary = (FrameLayout) findViewById(R.id.main_page_frame_right);
    this.seperator = findViewById(R.id.main_page_seperator);

    //Setup forum background
    final String forumWallpaper = this.application.getSession().getServer().serverWallpaper;
    final String forumBackground = this.application.getSession().getServer().serverBackground;
    if (forumBackground != null && forumBackground.contains("#") && forumBackground.length() == 7) {
        this.mDrawerLayout.setBackgroundColor(Color.parseColor(forumBackground));
    } else {
        this.mDrawerLayout.setBackgroundColor(Color.parseColor(getString(R.string.default_background)));
    }

    if (forumWallpaper != null && forumWallpaper.contains("http")) {
        final ImageView mainSwipeImageBackground = (ImageView) findViewById(R.id.main_swipe_image_background);
        final String imageUrl = forumWallpaper;
        ImageLoader.getInstance().displayImage(imageUrl, mainSwipeImageBackground);
    } else {
        findViewById(R.id.main_swipe_image_background).setVisibility(View.GONE);
    }

    this.setupSlidingDrawer();

    if (this.application.getStackManager().getBackStackSize(this.backStackId) == 0) {
        final Bundle bundle = this.initializeNewSession(appPreferences);
        this.loadCategory(bundle, "NEW_SESSION", false);
        //application.stackManager.addToBackstack(backStackId, BackStackManager.BackStackItem.BACKSTACK_TYPE_FORUM,bundle);
    } else {
        this.recoverBackstack();
    }

    final Bundle parms = getIntent().getExtras();
    if (parms != null) {
        if (parms.containsKey("stealing")) {
            final Boolean stealing = parms.getBoolean("stealing");

            if (stealing) {
                final String stealingLocation = parms.getString("stealing_location", "0");
                final String stealingType = parms.getString("stealing_type", "0");
                final boolean locationNumeric = isNumeric(stealingLocation);

                if (stealingType.contentEquals("forum") && locationNumeric
                        && !stealingLocation.contentEquals("0")) {
                    this.loadTopicItem(Category.builder().id(stealingLocation).name("External Link").build());
                }
                if (stealingType.contentEquals("topic") && locationNumeric
                        && !stealingLocation.contentEquals("0")) {
                    this.loadTopicItem(Topic.builder().id(stealingLocation).title("External Link").build());
                }
            }
        }
    }
    //Juice up gesture listener
    this.enableGestures();
}

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

private void handleIntent(Intent intent, boolean isNew, boolean restore) {
    boolean pushOpened = false;

    Integer push_user_id = 0;/*from w ww  .  j  a va  2 s.  co m*/
    Integer push_chat_id = 0;
    Integer push_enc_id = 0;
    Integer open_settings = 0;

    photoPath = null;
    videoPath = null;
    sendingText = null;
    documentPath = null;
    imagesPathArray = null;
    documentsPathArray = null;

    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("text/plain")) {
                String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                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 {
                    error = true;
                }
            } else 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<String>();
                        BufferedReader bufferedReader = new BufferedReader(
                                new InputStreamReader(stream, "UTF-8"));
                        String line = null;
                        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 = Utilities.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);
                                }
                            }
                        }
                        if (name != null && !phones.isEmpty()) {
                            contactsToSend = new ArrayList<TLRPC.User>();
                            for (String phone : phones) {
                                TLRPC.User user = new TLRPC.TL_userContact();
                                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 {
                Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM);
                if (parcelable == null) {
                    return;
                }
                String path = null;
                if (!(parcelable instanceof Uri)) {
                    parcelable = Uri.parse(parcelable.toString());
                }
                if (parcelable != null && type != null && type.startsWith("image/")) {
                    photoPath = (Uri) parcelable;
                } else {
                    path = Utilities.getPath((Uri) parcelable);
                    if (path != null) {
                        if (path.startsWith("file:")) {
                            path = path.replace("file://", "");
                        }
                        if (type != null && type.startsWith("video/")) {
                            videoPath = path;
                        } else {
                            documentPath = path;
                        }
                    } else {
                        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) {
                    if (type != null && type.startsWith("image/")) {
                        Uri[] uris2 = new Uri[uris.size()];
                        for (int i = 0; i < uris2.length; i++) {
                            Parcelable parcelable = uris.get(i);
                            if (!(parcelable instanceof Uri)) {
                                parcelable = Uri.parse(parcelable.toString());
                            }
                            uris2[i] = (Uri) parcelable;
                        }
                        imagesPathArray = uris2;
                    } else {
                        String[] uris2 = new String[uris.size()];
                        for (int i = 0; i < uris2.length; i++) {
                            Parcelable parcelable = uris.get(i);
                            if (!(parcelable instanceof Uri)) {
                                parcelable = Uri.parse(parcelable.toString());
                            }
                            String path = Utilities.getPath((Uri) parcelable);
                            if (path != null) {
                                if (path.startsWith("file:")) {
                                    path = path.replace("file://", "");
                                }
                                uris2[i] = path;
                            }
                        }
                        documentsPathArray = uris2;
                    }
                } 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())) {
            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(MessagesController.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;
        }
    }

    if (getIntent().getAction() != null && getIntent().getAction().startsWith("com.tmessages.openchat")
            && (getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0 && !restore) {
        int chatId = getIntent().getIntExtra("chatId", 0);
        int userId = getIntent().getIntExtra("userId", 0);
        int encId = getIntent().getIntExtra("encId", 0);
        if (chatId != 0) {
            TLRPC.Chat chat = MessagesController.getInstance().chats.get(chatId);
            if (chat != null) {
                NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
                push_chat_id = chatId;
            }
        } else if (userId != 0) {
            TLRPC.User user = MessagesController.getInstance().users.get(userId);
            if (user != null) {
                NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
                push_user_id = userId;
            }
        } else if (encId != 0) {
            TLRPC.EncryptedChat chat = MessagesController.getInstance().encryptedChats.get(encId);
            if (chat != null) {
                NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
                push_enc_id = encId;
            }
        }
    }

    if (push_user_id != 0) {
        if (push_user_id == UserConfig.clientUserId) {
            open_settings = 1;
        } else {
            ChatActivity fragment = new ChatActivity();
            Bundle bundle = new Bundle();
            bundle.putInt("user_id", push_user_id);
            fragment.setArguments(bundle);
            if (fragment.onFragmentCreate()) {
                pushOpened = true;
                ApplicationLoader.fragmentsStack.add(fragment);
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
            }
        }
    } else if (push_chat_id != 0) {
        ChatActivity fragment = new ChatActivity();
        Bundle bundle = new Bundle();
        bundle.putInt("chat_id", push_chat_id);
        fragment.setArguments(bundle);
        if (fragment.onFragmentCreate()) {
            pushOpened = true;
            ApplicationLoader.fragmentsStack.add(fragment);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
        }
    } else if (push_enc_id != 0) {
        ChatActivity fragment = new ChatActivity();
        Bundle bundle = new Bundle();
        bundle.putInt("enc_id", push_enc_id);
        fragment.setArguments(bundle);
        if (fragment.onFragmentCreate()) {
            pushOpened = true;
            ApplicationLoader.fragmentsStack.add(fragment);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss();
        }
    }
    if (videoPath != null || photoPath != null || sendingText != null || documentPath != null
            || documentsPathArray != null || imagesPathArray != null || contactsToSend != null) {
        MessagesActivity fragment = new MessagesActivity();
        fragment.selectAlertString = R.string.ForwardMessagesTo;
        fragment.selectAlertStringDesc = "ForwardMessagesTo";
        fragment.animationType = 1;
        Bundle args = new Bundle();
        args.putBoolean("onlySelect", true);
        fragment.setArguments(args);
        fragment.delegate = this;
        ApplicationLoader.fragmentsStack.add(fragment);
        fragment.onFragmentCreate();
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag())
                .commitAllowingStateLoss();
        pushOpened = true;
    }
    if (open_settings != 0) {
        SettingsActivity fragment = new SettingsActivity();
        ApplicationLoader.fragmentsStack.add(fragment);
        fragment.onFragmentCreate();
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "settings")
                .commitAllowingStateLoss();
        pushOpened = true;
    }
    if (!pushOpened && !isNew) {
        BaseFragment fragment = ApplicationLoader.fragmentsStack
                .get(ApplicationLoader.fragmentsStack.size() - 1);
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag())
                .commitAllowingStateLoss();
    }

    getIntent().setAction(null);
}

From source file:org.alfresco.mobile.android.application.manager.ActionManager.java

public static void actionSendDocuments(Fragment fr, List<File> files) {
    if (files.size() == 1) {
        actionSendDocument(fr, files.get(0));
        return;//from  w  w  w .ja  v  a 2  s . com
    }

    try {
        Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE);
        ArrayList<Uri> uris = new ArrayList<Uri>();
        // convert from paths to Android friendly Parcelable Uri's
        for (File file : files) {
            Uri u = Uri.fromFile(file);
            uris.add(u);
        }
        i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        i.setType(MimeTypeManager.getMIMEType(fr.getActivity(), "text/plain"));
        fr.getActivity()
                .startActivity(Intent.createChooser(i, fr.getActivity().getText(R.string.share_content)));
    } catch (ActivityNotFoundException e) {
        MessengerManager.showToast(fr.getActivity(), R.string.error_unable_share_content);
    }
}

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

/**
 * Notes sharing//from  w  ww. j  a  v  a2  s.  co m
 */
public void shareNote(Note note) {

    String titleText = note.getTitle();

    String contentText = titleText + System.getProperty("line.separator") + note.getContent();

    Intent shareIntent = new Intent();
    // Prepare sharing intent with only text
    if (note.getAttachmentsList().size() == 0) {
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");

        // Intent with single image attachment
    } else if (note.getAttachmentsList().size() == 1) {
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType(note.getAttachmentsList().get(0).getMime_type());
        shareIntent.putExtra(Intent.EXTRA_STREAM, note.getAttachmentsList().get(0).getUri());

        // Intent with multiple images
    } else if (note.getAttachmentsList().size() > 1) {
        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
        ArrayList<Uri> uris = new ArrayList<>();
        // A check to decide the mime type of attachments to share is done here
        HashMap<String, Boolean> mimeTypes = new HashMap<>();
        for (Attachment attachment : note.getAttachmentsList()) {
            uris.add(attachment.getUri());
            mimeTypes.put(attachment.getMime_type(), true);
        }
        // If many mime types are present a general type is assigned to intent
        if (mimeTypes.size() > 1) {
            shareIntent.setType("*/*");
        } else {
            shareIntent.setType((String) mimeTypes.keySet().toArray()[0]);
        }

        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    }
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText);
    shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);

    startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.share_message_chooser)));
}