Example usage for android.content Intent createChooser

List of usage examples for android.content Intent createChooser

Introduction

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

Prototype

public static Intent createChooser(Intent target, CharSequence title) 

Source Link

Document

Convenience function for creating a #ACTION_CHOOSER Intent.

Usage

From source file:co.dilaver.quoter.activities.ShareActivity.java

private void save() {

    previewLayout.setDrawingCacheEnabled(true);
    previewLayout.buildDrawingCache();//from  ww  w .j  a v a 2  s. c o  m
    Bitmap bmp = Bitmap.createBitmap(previewLayout.getDrawingCache());
    previewLayout.setDrawingCacheEnabled(false);

    ContextWrapper cw = new ContextWrapper(this);
    File directory = cw.getExternalFilesDir(null);
    if (!directory.exists()) {
        directory.mkdir();
    }
    File image = new File(directory, "image.jpg");

    FileOutputStream fos;
    try {
        fos = new FileOutputStream(image);
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.close();
    } catch (Exception e) {
        Log.e(TAG, e.getMessage(), e);
    }

    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + image.getAbsolutePath()));
    shareIntent.setType("image/jpeg");
    startActivity(Intent.createChooser(shareIntent, getString(R.string.str_ShareWith)));
}

From source file:com.dwdesign.tweetings.fragment.ConversationFragment.java

public void linkGenerationComplete(String url) {
    if (isShare == false) {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, account_id);
        bundle.putString(INTENT_KEY_TEXT, url);
        intent.putExtras(bundle);//from  w ww.  j a v a2  s.c om
        startActivity(intent);
    } else {
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, url);
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
    }
}

From source file:com.danvelazco.fbwrapper.activity.BaseFacebookWebViewActivity.java

/**
 * Allows us to share the page that's currently opened
 * using the ACTION_SEND share intent.//w  w  w  .ja v  a  2s.  co  m
 */
protected void shareCurrentPage() {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("text/plain");
    i.putExtra(Intent.EXTRA_SUBJECT, R.string.share_action_subject);
    i.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
    startActivity(Intent.createChooser(i, getString(R.string.share_action)));
}

From source file:com.support.android.designlibdemo.activities.CampaignDetailActivity.java

public void setupShareIntent() {
    // Fetch Bitmap Uri locally
    ImageView ivImage = (ImageView) findViewById(R.id.ivCampaighnImage);
    // Get access to the URI for the bitmap
    Uri bmpUri = getLocalBitmapUri(ivImage);
    if (bmpUri != null) {
        // Construct a ShareIntent with link to image
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, campaign.getTitle());
        shareIntent.putExtra(Intent.EXTRA_TEXT, campaign.getCampaignUrl());
        shareIntent.setType("image/*");
        // Launch sharing dialog for image
        startActivity(Intent.createChooser(shareIntent, "send"));
    } else {//ww w .  j  a va2s .  c  om
        Toast.makeText(this, "Some error occured during sharing", Toast.LENGTH_LONG).show();

    }

}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.WalletActivity.java

public void handleExportTransactions() {

    // Create CSV file from transactions

    final File file = new File(Constants.Files.EXTERNAL_WALLET_BACKUP_DIR,
            Constants.Files.TX_EXPORT_NAME + "-" + getFileDate() + ".csv");

    try {/*w  w w . j  a  v  a 2 s.c  o m*/

        final BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        writer.append("Date,Label,Amount (" + MonetaryFormat.CODE_PPC + "),Fee (" + MonetaryFormat.CODE_PPC
                + "),Address,Transaction Hash,Confirmations\n");

        if (txListAdapter == null || txListAdapter.transactions.isEmpty()) {
            longToast(R.string.export_transactions_mail_intent_failed);
            log.error("exporting transactions failed");
            return;
        }

        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm z");
        dateFormat.setTimeZone(TimeZone.getDefault());

        for (Transaction tx : txListAdapter.transactions) {

            TransactionsListAdapter.TransactionCacheEntry txCache = txListAdapter.getTxCache(tx);
            String memo = tx.getMemo() == null ? "" : StringEscapeUtils.escapeCsv(tx.getMemo());
            String fee = tx.getFee() == null ? "" : tx.getFee().toPlainString();
            String address = txCache.address == null ? getString(R.string.export_transactions_unknown)
                    : txCache.address.toString();

            writer.append(dateFormat.format(tx.getUpdateTime()) + ",");
            writer.append(memo + ",");
            writer.append(txCache.value.toPlainString() + ",");
            writer.append(fee + ",");
            writer.append(address + ",");
            writer.append(tx.getHash().toString() + ",");
            writer.append(tx.getConfidence().getDepthInBlocks() + "\n");

        }

        writer.flush();
        writer.close();

    } catch (IOException x) {
        longToast(R.string.export_transactions_mail_intent_failed);
        log.error("exporting transactions failed", x);
        return;
    }

    final DialogBuilder dialog = new DialogBuilder(this);
    dialog.setMessage(Html.fromHtml(getString(R.string.export_transactions_dialog_success, file)));

    dialog.setPositiveButton(WholeStringBuilder.bold(getString(R.string.export_keys_dialog_button_archive)),
            new OnClickListener() {

                @Override
                public void onClick(final DialogInterface dialog, final int which) {

                    final Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.export_transactions_mail_subject));
                    intent.putExtra(Intent.EXTRA_TEXT,
                            makeEmailText(getString(R.string.export_transactions_mail_text)));
                    intent.setType(Constants.MIMETYPE_TX_EXPORT);
                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

                    try {
                        startActivity(Intent.createChooser(intent,
                                getString(R.string.export_transactions_mail_intent_chooser)));
                        log.info("invoked chooser for exporting transactions");
                    } catch (final Exception x) {
                        longToast(R.string.export_transactions_mail_intent_failed);
                        log.error("exporting transactions failed", x);
                    }

                }

            });

    dialog.setNegativeButton(R.string.button_dismiss, null);
    dialog.show();

}

From source file:com.antew.redditinpictures.library.ui.ImageViewerActivity.java

/**
 * Handler for when the user selects an item from the ActionBar.
 * <p>// w  w w  . j  av a  2  s.  co  m
 * The default functionality implements:<br>
 * - Toggling the swipe lock on the ViewPager via toggleViewPagerLock()<br>
 * - Sharing the post via the Android ACTION_SEND intent, the URL shared is provided by
 * subclasses via {@link #getUrlForSharing()}<br>
 * - Viewing the post in a Web browser (the URL is provided by subclasses from
 * {@link #getPostUri()} <br>
 * - Displaying a dialog to get the filename to use when saving an image, subclasses will
 * implement {@link #onFinishSaveImageDialog(String)}
 * </p>
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        EasyTracker.getInstance(this)
                .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                        Constants.Analytics.Action.HOME, null, null).build());
        finish();
        return true;
    case R.id.lock_viewpager:
        if (mPager.isSwipingEnabled()) {
            EasyTracker.getInstance(this)
                    .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                            Constants.Analytics.Action.TOGGLE_SWIPING, Constants.Analytics.Label.DISABLED, null)
                            .build());
        } else {
            EasyTracker.getInstance(this)
                    .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                            Constants.Analytics.Action.TOGGLE_SWIPING, Constants.Analytics.Label.ENABLED, null)
                            .build());
        }

        // Lock or unlock swiping in the ViewPager
        setSwipingState(!mPager.isSwipingEnabled(), true);
        return true;
    case R.id.share_post:
        EasyTracker.getInstance(this)
                .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                        Constants.Analytics.Action.SHARE_POST, getSubreddit(), null).build());
        String subject = getString(R.string.check_out_this_image);
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, subject + " " + getUrlForSharing());
        startActivity(Intent.createChooser(intent, getString(R.string.share_using_)));
        return true;
    case R.id.view_post:
        EasyTracker
                .getInstance(this).send(
                        MapBuilder
                                .createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                                        Constants.Analytics.Action.OPEN_POST_EXTERNAL, getSubreddit(), null)
                                .build());
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, getPostUri());
        startActivity(browserIntent);
        return true;
    case R.id.save_post:
        EasyTracker.getInstance(this)
                .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                        Constants.Analytics.Action.SAVE_POST, getSubreddit(), null).build());
        handleSaveImage();
        return true;
    case R.id.report_image:
        EasyTracker.getInstance(this)
                .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                        Constants.Analytics.Action.REPORT_POST, getSubreddit(), null).build());
        new Thread(new Runnable() {
            @Override
            public void run() {
                reportCurrentItem();
            }
        }).start();
        Toast.makeText(this, R.string.image_display_issue_reported, Toast.LENGTH_LONG).show();
        return true;
    default:
        return false;
    }
}

From source file:com.z.stproperty.PropertyDetail.java

/**
 * User can share this property details with their friends through email as well
 * and can choose other options like whats-app, drop-box etc as well
 *//*from ww  w  .j a  v a 2s  .  c  o  m*/
private void shareWithEmail() {
    try {
        String path = Images.Media.insertImage(getContentResolver(), SharedFunction.loadBitmap(shareImageLink),
                "title", null);
        Uri screenshotUri = Uri.parse(path);
        String shareContent = title + "\n\n" + prurl + "\n\n" + price + "\n\n";
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/png");
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "" });
        intent.putExtra(Intent.EXTRA_SUBJECT, "Property to share with you");
        intent.putExtra(Intent.EXTRA_TEXT,
                "I think you might be interested in a property advertised on STProperty \n\n" + shareContent);
        intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
        SharedFunction.postAnalytics(PropertyDetail.this, "Lead", "Email Share", title);
        startActivity(Intent.createChooser(intent, ""));
    } catch (Exception e) {
        Log.e(this.getClass().getSimpleName(), e.getLocalizedMessage(), e);
    }
}

From source file:nl.sogeti.android.gpstracker.actions.ShareTrack.java

private void sendFile(Uri fileUri, String body, String contentType) {
    Intent sendActionIntent = new Intent(Intent.ACTION_SEND);
    sendActionIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject));
    sendActionIntent.putExtra(Intent.EXTRA_TEXT, body);
    sendActionIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
    sendActionIntent.setType(contentType);
    startActivity(Intent.createChooser(sendActionIntent, getString(R.string.sender_chooser)));
}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

/**
 * Open file from OTG//from   ww w  .  j  a  v a 2 s  . c  o  m
 */
public static void openunknown(DocumentFile f, Context c, boolean forcechooser, boolean useNewStack) {
    Intent chooserIntent = new Intent();
    chooserIntent.setAction(Intent.ACTION_VIEW);
    chooserIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    String type = f.getType();
    if (type != null && type.trim().length() != 0 && !type.equals("*/*")) {
        chooserIntent.setDataAndType(f.getUri(), type);
        Intent activityIntent;
        if (forcechooser) {
            if (useNewStack)
                applyNewDocFlag(chooserIntent);
            activityIntent = Intent.createChooser(chooserIntent, c.getString(R.string.openwith));
        } else {
            activityIntent = chooserIntent;
            if (useNewStack)
                applyNewDocFlag(chooserIntent);
        }

        try {
            c.startActivity(activityIntent);
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show();
            openWith(f, c, useNewStack);
        }
    } else {
        openWith(f, c, useNewStack);
    }
}